The purpose of this assignment is to analyze the relationship between risk and return of different assets as well as the benefits of diversification. It is broken into several steps. For each step, I provide you with an example showing what code you might use to complete the step in R.

You can always copy the code and run it in R and it should work on your computer. The final product will be a link that you submit to me containing your analysis.

Step 1 - Get the Data

I’ve provided data on the price of three different asset classes:

Your job is to run through this exercise using the data I’ve provided and then repeat the exercise with your own data on assets that you choose (individual stocks or exchange traded funds).

Step 1.A - Find your data

Do this step after you’ve worked through the problem using the data I provide. Your raw data should consist of one column with an index of the month and several other columns with the closing price of your assets from the last day in each month

  • Locate the data (FRED, Yahoo! Finance, Bloomberg Terminal)
  • Make a .csv file using excel.
  • Optional: discover the power of R by reading this

Step 1.B - Load the data into R

# Import csv file using the read.csv() function, call the data frame assetdata
# You will replace the url in this function with a file path to your data file

assetData=read.csv("http://dl.dropboxusercontent.com/u/3862114/assetprices.csv")

# Tell R to treat this data as a time series
tsPrices = zoo(assetData[,c(2:5)], order.by = assetData$month)

Step 2 Compute Monthly Returns

In this step you’ll compute the one-year continuously compounded equivalent rate of return for each asset in each month.

# Takes the log of all values and then take the first difference versus 12 months ago
tsReturns = diff(log(tsPrices), lag=12)
returns = data.frame(tsReturns)

Step 3 Compute Expected Return and Risk

Now we’ll investigate how expected return and our measure of risk (standard deviation) are related across assets.

# Compute the mean returns for each asset
avgReturns=apply(returns,2,mean)
# Compute the standard deviations for each asset
sdReturns=apply(returns,2,sd)
# Plot standard deviation on x-axis and expected return on y-axis
plot(avgReturns~sdReturns, xlim=c(0,.5), ylim=c(0,.12))
text(sdReturns, avgReturns, names(avgReturns), pos=3)

plot of chunk unnamed-chunk-4

Note: For now, pretend that the CPI is US treasuries.

Question

Does there appear to be a trade off between risk and return? Given what people like (and don’t like), does this trade off make sense?

Question

Does one of the three assets seem like a bad deal relative to the other two? Explain Briefly.

Step 4 Simulate a Portfolio of all 3 assets

# Chose allocation weights
wUsEquity = .6
wUsBond = 0.2
wRowEquity = 0.2
W = c(wUsEquity, wUsBond, wRowEquity)
W = W/sum(W)
# Simulate 1000 30-year holding periods for the portfolio 
simReturns=do(100)*(colSums(returns[sample(nrow(returns),30),c(1:3)]))
## Loading required package: parallel
simReturns=(rowSums(simReturns*W))/30
favstats(~simReturns)
##       min      Q1  median      Q3    max    mean     sd   n missing
##  -0.01302 0.06635 0.08283 0.09606 0.1426 0.08067 0.0248 100       0
## Add portfolio to the scatter plot
p = c(sd(simReturns),mean(simReturns))
plot(avgReturns~sdReturns, xlim=c(0,.5), ylim=c(0,.12))
text(sdReturns, avgReturns, names(avgReturns), pos=3)
points(p[1],p[2])
text(p[1],p[2], "Portfolio", pos=3)

plot of chunk unnamed-chunk-5

Idea for future work.

Set up a function that gives portfolio sd and mean Use the manipulate() function to allow users to adjust the weights so they can see how the location of Portfolio changes.

Note: I accomplished this, but haven’t managed to include it in a reasonable way on this document.