Session Ready
Exercise

Exploring monthly returns of the 30 DJIA stocks

The 1991-2015 monthly returns on the 30 DJIA stocks are available in the workspace as the variable returns. This exercise will help you get comfortable with the data that you will be using for the remainder of the exercises.

Recall that if we compute the means column by column using colMeans(returns), or apply(returns, 2, "mean"), you then obtain the average return per asset. In this exercise, you will be computing the mean per row. You can do this similarly using the function rowMeans() and supplying the argument 1 instead of two to indicate row-wise calculations in the apply() function. By doing so, you obtain the time series of returns for the equally weighted portfolio.

Instructions
100 XP
  • Verify that returns is an object of the xts-class using the function class().
  • Investigate the dimensions of returns using dim().
  • Create a vector of row means of returns using the function rowMeans(). Assign this to ew_preturns. Note that you could have used apply() here as well.
  • The solution obtained from rowMeans() is a numeric vector. Cast it back to a xts object using xts with time series stamp equal to the dates in returns.
  • Plot ew_preturns using plot.zoo().