Get startedGet started for free

Who did it?

In the previous video, you saw the difference between a capital allocation budget and a risk budget. In this exercise, you will construct a risk budget, and discover how large each asset's percent risk contribution is in the total portfolio volatility.

For this last exercise, you will calculate the risk contributions for a portfolio that is again invested 40% in equities, 40% in bonds, 10% in real estate, and 10% in commodities. The function StdDev() plays an important role in this exercise. The StdDev() function creates a list of the assets' standard deviation ($StdDev), their risk contribution ($contribution), and their percent risk contribution ($pct_contrib_StdDev).

You will be using three arguments in the StdDev() function to do this calculation. The first is R, a vector, matrix, data frame, time series, or zoo object of returns. The second is portfolio_method, which you will set to component, and the third is weights.

The object returns is loaded in your workspace.

This exercise is part of the course

Introduction to Portfolio Analysis in R

View Course

Exercise instructions

  • Create a vector of the portfolio weights called weights. Remember, order matters!
  • Calculate your volatility budget using StdDev() on the return series returns. Set portfolio_method = "component" and weights equal to the created vector of weights. Call this vol_budget.
  • Combine the weights and the percentage risk contributions in a table called weights_percrisk using cbind().
  • Print the table and note how different the percentage risk contributions are compared to the portfolio weights.

Hands-on interactive exercise

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

# Create portfolio weights


# Create volatility budget
vol_budget <- StdDev(___, portfolio_method = "___", weights = ___)

# Make a table of weights and risk contribution

colnames(weights_percrisk) <- c("weights", "perc vol contrib")

# Print the table
Edit and Run Code