Minimizing CVaR

This exercise will give you practice with PyPortfolioOpt's tools for CVaR minimization as a risk management objective.

You'll load the pypfopt.efficient_frontier module and retrieve the EfficientCVaR class, creating an instance of the class using the investment bank assets over the 2005 - 2010 period.

You'll then use the instance's min_cvar() method to find the optimal portfolio weights that minimize the CVaR.

Portfolio asset returns are in the returns vector--this exercise also uses a names dictionary to map portfolio weights to bank names.

Diese Übung ist Teil des Kurses

Quantitative Risk Management in Python

Kurs anzeigen

Anleitung zur Übung

  • Import the EfficientCVaR class from pypfopt.efficient_frontier.
  • Create the EfficientCVaR class instance ec using returns; note you don't need expected_returns, since the objective function is different from mean-variance optimization.
  • Find and display the optimal portfolio using ec's .min_cvar() method.

Interaktive Übung zum Anfassen

Probieren Sie diese Übung aus, indem Sie diesen Beispielcode ausführen.

# Import the EfficientCVaR class
from pypfopt.____ import EfficientCVaR

# Create the efficient frontier for CVaR minimization
ec = ____(None, ____)

# Find the cVaR-minimizing portfolio weights at the default 95% confidence level
optimal_weights = ec.____()

# Map the values in optimal_weights to the bank names
optimal_weights = { names[i] : optimal_weights[i] for i in optimal_weights}

# Display the optimal weights
print(optimal_weights)