Session Ready
Exercise

Driver 2: The choice of portfolio weights

Investors can optimize the choice of weight to obtain the highest risk-adjusted return, as measured by the portfolio Sharpe ratio.

In the special case of investing the total portfolio value in only two assets, there is only one weight to determine, because the weight on the second asset equals one minus the weight of the first asset.

Let us do this in the case of a portfolio invested in U.S. equities and U.S. bonds. We will be using the brute force approach of trying a large number of possible weights and keeping the weight that yields the highest value for the portfolio Sharpe ratio (assuming a zero risk-free rate).

Instructions
100 XP
  • Create a vector called grid using seq() that begins at 0, ends at 1, by an increment of 0.01.
  • Initialize empty vector vsharpe with the same length as grid. A popular way of doing this is by creating a vector that contains NA's using function rep(). You will replace these NA's in the loop that you will create next.
  • In the for loop, you will compute the Sharpe ratio for each of the possible weights in grid. The first command in the for-loop selects the i-th element of grid and stores it in object weight, which changes in each iteration.
  • You want to see how the portfolio return changes with a changing weight. Create an object preturns that equals the sum of weight times returns_equities, and (1-weight) times returns_bonds.
  • Next, you will replace the NAs in vsharpe with the annualized Sharpe ratio (SharpeRatio.annualized()) of preturns.
  • Fill in the plot function where potential weights (grid) is plotted on the x-axis and the Sharpe ratios on the y-axis.