최적 Sharpe 비율과 함께 효율적 프론티어 그리기
이제 효율적 프론티어를 다시 그리되, 가장 높은 Sharpe 지수를 갖는 포트폴리오에 마커를 추가해 보겠습니다. 데이터를 시각화하면 더 잘 이해하는 데 항상 도움이 됩니다.
효율적 프론티어는 x축에 포트폴리오 변동성, y축에 포트폴리오 수익률을 두는 산점도로 표시한다는 점을 기억하세요. 날짜는 covariances.keys()에서 가져오며, 날짜를 얻기 위해 portfolio_returns 등 다른 사전들을 사용해도 됩니다. 그런 다음 portfolio_volatility와 portfolio_returns에서 최신 날짜의 변동성과 수익률을 가져옵니다. 마지막으로 max_sharpe_idxs[date]에서 최적 Sharpe 지수를 갖는 포트폴리오의 인덱스를 구해, plt.scatter()로 모두 시각화합니다.
이 연습은 강의의 일부입니다
Python으로 배우는 금융 분야 Machine Learning
연습 안내
- 최신
date의 포트폴리오 변동성으로cur_volatility를 설정하세요. - x축에 변동성, y축에 수익률을 두어 "효율적 프론티어" 플롯을 그리세요.
max_sharpe_idxs에서 최신date의 최적 포트폴리오 인덱스를 가져오세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Get most recent (current) returns and volatility
date = sorted(covariances.keys())[-1]
cur_returns = portfolio_returns[date]
cur_volatility = ____
# Plot efficient frontier with sharpe as point
plt.scatter(x=____, y=____, alpha=0.1, color='blue')
best_idx = max_sharpe_idxs[____]
# Place an orange "X" on the point with the best Sharpe ratio
plt.scatter(x=cur_volatility[best_idx], y=cur_returns[best_idx], marker='x', color='orange')
plt.xlabel('Volatility')
plt.ylabel('Returns')
plt.show()