程序代写 ECON30025/ECOM90020

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
Assignment 2, 2022 Due 11:59pm, May 23, 2022
This assignment has 40 possible points and is worth 20% of your final grade for those in ECON30025.
This assignment has 50 possible points and is worth 25% of your final grade for those in ECOM90020.

Copyright By PowCoder代写 加微信 powcoder

Make sure to include the coversheet with your answers. Read the instructions on the coversheet. Try to keep your answers short and clear. Please submit copies of all the programs. Write not more than 5/8 pages of text (not including the programs) and cut and paste any results into a word document. The program codes should be included as an appendix. For modifications to existing code add comments, indents and spaces so they would look like ones that you would write for someone else to use. We will be marking the code.
All students are to submit answers to questions 1 to 5 .
Students enrolled in ECOM90020 are also to answer extra parts of questions 2 and 4.
Figure 1 Map of the Skeezix’s Park amusement attraction is given below. The attractions are located at the nodes identified by the letters A through H.
Skeezix’s Park

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
Question 1. (10pts)
Consider the map in Figure 1 of an amusement attraction called Skeezix’s Park. Where the paths back and forth between the attractions are given by the lines and the arrows indicate the direction of paths between them that are either one-way or both ways.
(a) (2pts) Using the page-rank methodology that orders websites based on the number of connections from a website to other websites describe how you would use this method to create an order of the different amusement locations at Skeezix’s Park based on the paths leading out of each site. What is the process for finding a stable solution?
(b) (2pts) How would you define the transition matrix in this case. Show the formula to use in this case.
(c) (4pts) Modify a Proc IML routine find the order of the attractions with the highest level of attendance to the lowest. Print out the transition matrix, the potential final steady state and total number of paths leading from each attraction. How does the final order of the sites match the number of paths to and from each site?
(d) (2pts) Given a person starts at site A and randomly chooses where to go next where will they be after 5 iterations? How can you represent this result?
Question 2. (10pts/15pts) (Only those in ECOM90020 need attempt parts f and g)
Answer the following questions also based on the map for Skeezix’s Park in Figure 1. Consider the following problem: There are 12 more cases of soft drink located in a warehouse at attraction C than needed and there is a demand for 3 cases at attractions G and H, and for 2 cases at attractions B, D, and E.
(a) (1pt) What method would you employ to find the least cost routes for these cases to meet this demand?
(b) (3pt) Determine the cost of transport between each attraction where the cost of transport is cost = 5 + 2*distance. Where the distance is the is the Euclidean distance as can be computed from the table of grid locations for each site shown below:
Attraction X Vertical Y Horizontal
A 4.6 10.1
B 9.6 20.6
C 22.7 9.1
D 24.4 22.8
E 34.7 18.8
F 39.8 26.6
G 40.8 16.7
H 40.8 8.0
Note: the IML function distance() will compute the matrix of Euclidian distances from a matrix of locations. (see the SAS documentation for details).
(c) (2pts) Define the equations or method you need to solve this problem and write a routine in Proc IML to solve for the least cost route for these deliveries. Assume that transporting the cases can only be done in the direction of the arrows.
(d) (2pts) What is the least cost route for moving the 12 cases? What is the total cost? (e) (2pts) Consider the situation when Skeezix’s Park needs to close, and all the
additional cases just delivered need to be returned to the warehouse. This means moving 3 2

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
cases from attractions G, and H, and 2 cases from B, D, and E back to location C. Is the cost for this and the routes taken the same as those you found for the answer to part d? If not, how do they differ?
*Additional related question for students in ECOM90020
Consider the original situation where the cost of moving the cases from the warehouse at C (i.e. 12 from C for 3 cases to G and H, and 2 cases to B, D, and E) is not exactly defined and we need to consider that it may be influenced by a random factor. Assume here that the cost is defined by cost = 2 * distance + u given u is a random factor generated by a uniform distribution with a mean of 5 that ranges from 2 to 8.
*(f) (3pt) Design a process for determining the distribution of the cost of moving the cases so that you can recompute the solution for different cost relationships. How would you modify the program you used in your answer to part (d)? (Hint: it would probably require inserting a do loop and writing out the results to a file.)
*(g) (2pts) Rerun the solution and construct the histogram of costs based on at least 50 iterations. What is the range of costs that would be incurred for this allocation and how does it compare to our original result reported in the answer to part (d) above.
Question 3. (10pts)
A supervisor at Skeezix’s Park can spend 15 minutes at each attraction and must move from one to the next based on an equal probability that they will go to any direction that they can (thus, they do not stay in one location for more than 15 minutes). They can move either way on all routes that end or begin at that attraction – that means they ignore the directions of the arrows and the distances between them.
(a) (2pts) Describe the method you can use to determine which attractions they spend the most time at if the probability of their movement is based on the number of paths that lead to each site and staying put?
(b) (2pts) Provide the details (i.e. formulae et cetera) of the algorithm you would use to solve for the probability that the supervisor will visit each site. For example, if they are at location A, they have a 1/3 probability of going to either B, C, or H.
(c) (3pts) Write a Proc IML routine to determine the probability that the supervisor will visit each attraction. Report the order of the sites from least visited to most visited.
(d) (3pts) Report the probability that the supervisor will visit each attraction over an 8- hour day. Does it matter where they start? Order the sites from highest frequency to lowest frequency of the supervisor visit. Plot how the probabilities that the supervisor will visit each site changes if the supervisor starts their day at attraction A.
Question 4 (5pts/10pts) (Only those in ECOM90020 need attempt part b).
By modifying the Tan_portfolio_nasdaq_22d.sas (see the appendix for this code) routine that uses the daily returns for 10 stocks, the NASDX index of stocks and the daily value of the annual yield on 10yr US treasury bonds as of April 27, 2022 answer the following.
(a) (5pts) Run this model to determine the optimal portfolio over the period from January 1, 2018 to April 25, 2022 and record the optimal portfolio and plot the results. Describe what you find. Which stocks appear to be outliers? Can you see why some stocks

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
are not included in the optimal portfolio? Is there anything odd about the recent acquisition by a famous entrepreneur who builds electric cars and spaceships?
*(b) (5pts) Re-run the analysis for the nine 6-month periods from January 2018 to April 25, 2022.1 Record the optimal portfolio weights and the optimal portfolio performance by period. (Hint: You might want to use a macro to speed up this process and remove the second proc IML step and the plots in the original program). Can you identify any influence of COVID or the recent events in Ukraine?
Question 5 (5pts)
Using the DEA program for tutorial 9 (Tute9_DEA.sas see the appendix for this code) to estimate efficiency measures for a sample of electric utilities, compute the efficiency measures when using the cost of the 3 inputs as opposed to the quantities used in the original program for the measures of the inputs. Note that the per unit prices of the inputs are included in the data set.
(a) (2 pts) Find the most efficient DMUs under the constant returns assumption and the variable returns assumption. How to these compare to the results we obtained as reported in the answers to tutorial 9 where we use the physical input measures? (Note just rerun Tute9_DEA.sas as is to obtain the original results).
(b) (1 pts) How does the inference of the returns to scale differ in this case as opposed to the results obtained in the original results found in the tute?
(c) (2 pts) What do we find in this case where we compare these efficiency measures to the alternative measure based on the ratio of output to cost?
1 Allow for the last period to be shorter.

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
Program to use for Question 4 (Tan_portfolio_nasdaq_22D.sas).
Define a macro that creates the daily returns for each stock
Read the data set defined by &id
Tan_portfolio_nasdaq_22D.sas
Data from https://www.nasdaq.com/market-activity/stocks/qcom/historical
on 27/4/22. To obtain data go to this site and ask for the maximum
historical daily data then download the csv file.
The DGS10 file comes from Fred – The St Reserve Bank data sets
at https://fred.stlouisfed.org/series/DGS10 .
Title “Tangent Portfolio with NASDAQ data” ;
%macro import(id);
filename csvFile url
“https://www.online.fbe.unimelb.edu.au/t_drive/ECOM/ECOM90020/data/stocks22/&id..csv”
termstr=crlf;
proc import datafile=csvFile out=&id replace dbms=csv; run;
Set the closing value of the stock to a variable with the name &id
and only keep the closing value and the date
data &id ; set &id ;
if &id = . then &id= close_last ;
keep date &id ;
Make sure the data are sorted by accending date
proc sort data=&id; by date ; run;
%mend import;
Use the import macro to read the separate files
Combine the separate files
%import(AAPL) ; %import(CSCO) ; %import(MSFT) ; %import(QCOM) ;
%import(SBUX) ;
%import(AMD) ; %import(AMZN) ; %import(NASDX) ; %import(TSLA) ;
%import(GOOGL) ;
%import(TWTR) ; %import(DGS10) ;
data total ;
merge AAPL CSCO MSFT QCOM SBUX AMD AMZN NASDX TSLA GOOGL TWTR DGS10 ;
DGS10 = “Daily 10-yr US treasury rate”
GOOGL = Alphabet (Google)
AAPL = SCO = Cisco
MSFT = Microsoft
QCOM = QualComm
SBUX = Starbucks
AMD = Advanced Micro Devices
AMZN = Amazon
TWTR = Twitter

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
NASDX = “Nasdaq-100 Index Fund”
TSLA = Tesla;
keep date AAPL CSCO MSFT QCOM SBUX AMD AMZN NASDX TSLA GOOGL TWTR DGS10;
read all var {&risk_free} where(_type_= “MEAN”) into f ;
The number of assets – a portfolio contains N assets
Define a list of the variables for the stocks
This can be changed if you want to try different combinations
%let stocks = AAPL CSCO MSFT QCOM SBUX AMD AMZN NASDX TSLA GOOGL TWTR ;
%let risk_free = DGS10 ;
%let dsname = returns ;
Use the daily price data to compute returns as daily values
data returns ; set total ;
format &stocks best12.6 ;
array price &stocks ;
do over price ;
* Multiply by the number of trading days in a year to make it by year;
price = (log(price) – log(lag(price))) * 261 ;
dgs10 = dgs10/100 ; * convert to proportions ;
Use proc corr to compute the mean and covariance of the stock series
You can modify the period over which you would like to perform the analysis
%let start_date=01JUL2012; %let end_date=25APR2022;* set the time limits;
proc corr data=&dsname(where=(“&start_date”d <= date <="&end_date"d )) outp=out1 cov ; var &stocks &risk_free; run; The original IML code for this example comes from: "Get Tangency Portfolio", SAS/IML ® 2017, by Shan, , and %let n_sim = 50000; /* set the number of simulations */ /**** Step title "Efficient Portfolio Frontier With Multiple Assets"; title2 "From &start_date to &end_date"; 1************************************************************************************/ proc iml; reset fuzz = 1e-6; Read the covariance and mean returns from the out1 data set use out1 ; read all var {&stocks} where((_type_ = "COV") & (_name_ ^= "&risk_free")) into cov[colname=names] ; read all var {&stocks} where((_type_ = "MEAN") & (_name_ ^= "&risk_free")) into return n = ncol(return); riskless rate government long-term bond rate is f print "Risk Free Average Return, " f ; print cov [c=names r=names]; print return [c=names]; J. Hirschberg Computational Economics and Business ECON30025/ECOM90020 portfolio_return is expect return of a porfolio portfolio_std is standard deviation of a porfolio con=repeat({0,1,1},1,n)||{. .,. .,0 1}; print "Constraints " con ; /* Initial value of x1,x2,... set to equal proportions optn = {1 2}; * define the options for NLPNRA routine ; xres is a solution if return code is > 0,(rc>0)
proc iml; reset fuzz = 1e-6; /*
Set up the same case as used above
*———————————————————————;
To get the tangency portfolio maximize slope of line
Define the function max_slope. x is the weight for each asset.
start max_slope(x) global(f,cov,return);
portfolio_return = sum(return#x);
portfolio_std = sqrt(x*cov*x`);
Calculate slope – riskless rate’s std is zero
k = (portfolio_return-f)/portfolio_std;
return (k);
*———————————————————————;
Constraint conditions – x1+x2… = 1 and 0<=x1<=1,0<=x2<=1,... to bound the portfolio to sum to 1 and range between 0 and 1. x = j(1,n,1/n); /* ----------------------------------------------------------------------; Maximize object function value using NLPNRA routine for optimisation call nlpnra(rc,xres,"max_slope",x,optn,con); /* ----------------------------------------------------------------------; Print the solution if rc>0
print rc[l = ‘Return Code’],
xres[l = ‘It is a Solution if Return Code > 0’ colnames=names format=percent8.2];
Op_return = sum(return#xres);
OP_std = sqrt(xres*cov*xres`);
Print ‘Optimal Results’ , ‘Return = ‘ Op_return ‘, Std = ‘ OP_std ;
save the solution for the following proc sgplot
if rc > 0 then do;
create want from xres; append from xres; close; end;
else print “Can’t find a solution”;
/**** Step 1 End ************************************************************************/
/**** Step 2 *****************************************************************************/
* Now confirm if the solution is right with the same data by simulating many portfolios
of n assets with the same average returns and covariance.
n_s = &n_sim ;

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
use out1 ;
read all var {&stocks} where((_type_ = “COV”)&(_name_ ^= “&risk_free”)) into
cov[colname=names] ;
read all var {&stocks} where((_type_ = “MEAN”)&(_name_ ^= “&risk_free”)) into return ;
read all var {&risk_free} where(_type_= “MEAN”) into f ;
n = ncol(return);
print “Average returns of the assets”, return [c=names format=percent8.2],
“Standard deviations”, (sqrt(vecdiag(cov))`) [c=names format=percent8.2];
actuals = return`||(sqrt(vecdiag(cov))) ;
make &n_sim random testing portfolios
reset fuzz;
temp = j(n_s,n,.);
call randgen(temp,’exp’);
x = temp/temp[,+]; x = x // I(n) ; * add portfolios of only one asset;
get portfolio’s expect return and std
n_s = n_s + n ;
portfolio = j(n_s,2,.);
do ii = 1 to n_s ;
portfolio[ii,1] = sum(return#x[ii,]);
portfolio[ii,2] = sqrt(x[ii,]*cov*x[ii,]`);
Define the efficient portfolio frontier as the limits to the portfolios based
on the convex hull algorithm that locates the values on the edge.
indices = cvexhull(portfolio);
hullIndices = indices[loc(indices>0)];
frontier = portfolio[hullIndices,];
Find the tangency portfolio’s expect return and std from earlier run
read all var _num_ into x;
tangency = j(1,2,.);
tangency[1] = sum(return#x);
tangency[2] = sqrt(x*cov*x`);
Save results for proc sgplot by writting out the simulated results
create frontier from frontier[c = {return std}];
append from frontier; close;
create tangency from tangency[c = {tang_return tang_std}];
append from tangency; close;
riskless = f||0;
create riskless from riskless[c = {riskless_return riskless_std}];
append from riskless; close;
create portfolio from portfolio[c = {return_s std_s}];
append from portfolio;close;
create actuals from actuals[c = {return_a std_a}];
append from actuals; close;
tnames = names`;
create names from tnames[c = {“name”}];
append from tnames; close;
Define k as the slope of line between riskless rate and tangency portfolio

Setup the plot of the simulated values
J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
k = (tangency[1]-riskless[1])/tangency[2];
call symputx(‘k’,k); * create the global value of &k ;
/**** Step 2 End ************************************************************************/
define data for plot by stacking the portfolios, the frontier, the tangency and
riskless data sets
data actuals ; merge actuals names ; run;
data sgplot;
set frontier tangency riskless portfolio actuals;
ods graphics LABELMAX=50100;
proc sgplot data = sgplot;
scatter x = std_s y = return_s/ name = ‘a’
legendlabel = “Simulated Portfolios”
markerattrs = graphdata3(size = 1 color=grey);
color=blue)
series x = std y = return/ smoothconnect lineattrs = graphdata1(thickness = 2
name = ‘b’ legendlabel = ‘Efficient Portfolio Frontier’;
scatter x = std_a y = return_a/ name = ‘c’ datalabel=name
DATALABELATTRS=(Color=red Family=Arial Size=10 Style=Italic Weight=Bold)
legendlabel = “Individual Assets”
markerattrs = graphdata3(symbol = star size = 6 );
keylegend ‘a’ ‘b’ ‘c’ / location = inside position = topleft across = 1;
yaxis label = ‘Expect Daily Return Of Portfolio’ grid valuesformat = percent8.2;
xaxis label = ‘Standard Deviation Of Portfolio’ grid valuesformat = percent8.2;
Setup the complex plot to demonstrate the frontier of the simulated values
proc sgplot data = sgplot;
scatter x = std_s y = return_s/ name = ‘d’
legendlabel = “Simulated Portfolios”
markerattrs = graphdata3(symbol = dot size = 1 color=grey);
lineparm x = riskless_std y = riskless_return slope = &k /
lineattrs = graphdata6(thickness = 2) name= ‘e’
legendlabel = ‘Capital Market Line’;
series x = std y = return/ smoothconnect lineattrs = graphdata1(thickness = 2)
name = ‘c’ legendlabel = ‘Efficient Portfolio Frontier’;
scatter x = riskless_std y = riskless_return/ name = ‘a’
legendlabel = “Average of &risk_free”
markerattrs = graphdata3(symbol = diamondfilled size = 12);
scatter x = tang_std y = tang_return/ name = ‘b’
legendlabel = ‘Tangency Portfolio’
markerattrs = graphdata2(symbol = starfilled size = 14);
scatter x = std_a y = return_a/ name = ‘f’ datalabel=name
legendlabel = “Individual Assets”
markerattrs = graphdata3(symbol = star size = 6 color=red);
keylegend ‘a’ ‘b’ ‘c’ ‘d’ ‘e’ ‘f’ / location = inside position = topleft across = 1;
yaxis label = ‘Expect Daily Return Of Portfolio’ grid valuesformat = percent8.2;
xaxis label = ‘Standard Deviation Of Portfolio’ grid valuesformat = percent8.2;

J. Hirschberg Computational Economics and Business ECON30025/ECOM90020
Program for question 5 (Tute9_DEA.sas)
/* Tute9_DEA

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com