CVaR 최소화
이번 연습 문제에서는 위험 관리 목표로 CVaR을 최소화하기 위해 PyPortfolioOpt 도구를 연습해 봅니다.
먼저 pypfopt.efficient_frontier 모듈에서 EfficientCVaR 클래스를 불러오고, 2005년부터 2010년까지의 투자은행 자산 데이터를 사용해 해당 클래스의 인스턴스를 생성해요.
그다음 인스턴스의 min_cvar() 메서드를 사용해 CVaR을 최소화하는 최적 포트폴리오 가중치를 찾습니다.
포트폴리오 자산 수익률은 returns 벡터에 들어 있으며, 이 연습 문제에서는 가중치를 은행 이름으로 매핑하기 위해 names 사전도 사용해요.
이 연습은 강의의 일부입니다
Python을 활용한 정량적 리스크 관리
연습 안내
pypfopt.efficient_frontier에서EfficientCVaR클래스를 가져오세요.- 목적 함수가 평균-분산 최적화와 다르므로
expected_returns가 필요하지 않다는 점에 유의하면서,returns를 사용해EfficientCVaR클래스 인스턴스ec를 생성하세요. ec의.min_cvar()메서드를 사용해 최적 포트폴리오를 찾고 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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)