효율적 경계와 금융 위기
이전에 투자은행 포트폴리오의 공분산 행렬을 금융 위기 전·중·후로 살펴보셨죠. 이제 효율적 경계를 시각화해, 위기가 동일한 기대수익률 대비 기본 위험 수준을 얼마나 크게 끌어올렸는지 보여 드리겠습니다.
PyPortfolioOpt의 pypfopt 라이브러리에서 Critical Line Algorithm(CLA) 객체를 사용해 위기 기간 중 효율적 경계를 구해 시각화하고, 이미 표시된 위기 이전 및 이후의 효율적 경계 산점도에 이를 추가할 거예요.
기대수익률 returns_during과 효율적 공분산 행렬 ecov_during, 그리고 pypfopt의 CLA 객체가 제공됩니다. (DataCamp의 플롯은 별도 창으로 확장해 가독성을 높일 수 있다는 점을 기억하세요.)
이 연습은 강의의 일부입니다
Python을 활용한 정량적 리스크 관리
연습 안내
- 기대수익률과 수익률의 효율적 공분산을 사용해 임계선 알고리즘(
CLA) 객체efficient_portfolio_during을 생성하세요. efficient_portfolio_during의 최소분산 포트폴리오를 출력하세요.efficient_portfolio_during의 효율적 경계를 계산하세요.- 위기 이전과 이후의 효율적 경계가 표시된 기존 산점도에 방금 계산한 효율적 경계 결과를 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Initialize the Crtical Line Algorithm object
efficient_portfolio_during = CLA(____, ecov_during)
# Find the minimum volatility portfolio weights and display them
print(efficient_portfolio_during.____)
# Compute the efficient frontier
(ret, vol, weights) = efficient_portfolio_during.____
# Add the frontier to the plot showing the 'before' and 'after' frontiers
plt.scatter(vol, ____, s = 4, c = 'g', marker = '.', label = 'During')
plt.legend()
plt.show()