Get startedGet started for free

The minimum variance and maximum Sharpe ratio portfolio

In the previous exercises, you computed the efficient frontier using a grid of target returns. The output of your calculation of the efficient frontier was a series of two vectors, vpm (vector of portfolio means), and vpsd (vector of standard deviations, or volatilities), and a matrix of weights called mweights. You will use these outputs to identify the portfolios with the least volatility, and the greatest Sharpe ratio, and then plot their weight allocation.

As a reminder, the Sharpe Ratio is found by taking the excess returns less than the risk-free rate, divided by the portfolio volatility.

This exercise is part of the course

Introduction to Portfolio Analysis in R

View Course

Exercise instructions

  • Create weights_minvar, which is the row in mweights where the standard deviation in minimized (vpsd == min(vpsd)).
  • Calculate the Sharpe ratio of portfolio returns when the risk-free rate is 0.75%. Call this vsr.
  • Create weights_max_sr as the row in mweights corresponding to the portfolio with the maximum Sharpe ratio in vsr. This can be solved in a similar fashion as the first instruction.
  • Create a bar plot of the weights that are greater than 1% in the weights_minvar portfolio, and create a bar plot of the weights that are greater than 1% in the weights_max_sr portfolio.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create weights_minvar as the portfolio with the least risk
weights_minvar <- mweights[___ == min(___), ]

# Calculate the Sharpe ratio
vsr <- (___ - ___) / vpsd

# Create weights_max_sr as the portfolio with the maximum Sharpe ratio
weights_max_sr <- mweights[___ == max(___)]

# Create bar plot of weights_minvar and weights_max_sr
par(mfrow = c(2, 1), mar = c(3, 2, 2, 1))
barplot(weights_minvar[weights_minvar > 0.01])
barplot(___[___ > 0.01])
 
Edit and Run Code