有效前沿与金融危机
此前,您已经检查了投资银行投资组合在金融危机前、期间和之后的协方差矩阵。现在,您将把这些变化可视化到有效前沿上,展示危机如何让在给定收益下的基线风险显著升高。
使用 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()