效率前緣與金融危機
先前你已經檢視過投資銀行投資組合在金融危機前、中、後的共變異數矩陣。現在你要把這些變化以效率前緣視覺化,並觀察危機如何讓在任一既定報酬下的基準風險明顯升高。
使用 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()