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.
Cet exercice fait partie du cours
Quantitative Risk Management in Python
Instructions
- Import the 
EfficientCVaRclass frompypfopt.efficient_frontier. - Create the 
EfficientCVaRclass instanceecusingreturns; note you don't needexpected_returns, since the objective function is different from mean-variance optimization. - Find and display the optimal portfolio using 
ec's.min_cvar()method. 
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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)