波动率与结构性突变
可视化波动率变化有助于揭示时间序列中可能的结构性突变点。通过识别波动率何时发生变化,您就能更有根据地选择断点,并据此开展进一步的统计分析(例如 Chow 检验)。
您将查看 2008–2009 年投资银行组合的两种波动率可视化,对应两组可用的组合权重:weights_with_citi 和 weights_without_citi。它们分别表示包含和不包含 Citibank 的等权重组合。正如您在第 1 章所见,Citibank 在该期间的四个资产中波动率最高。
2008–2009 年包含 Citibank 的投资组合价格以 prices_with_citi 提供,不包含 Citibank 的以 prices_without_citi 提供。
本练习是课程的一部分
Python 中的定量风险管理
练习说明
- 使用
weights_with_citi和weights_without_citi求出两个投资组合的收益序列。 - 分别计算两个投资组合 30 天滚动窗口的标准差。
- 将两个 Pandas
Series对象合并为一个名为 "vol" 的 DataFrame 对象。 - 绘制
vol对象的内容,以比较两组投资组合随时间的波动率。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Find the time series of returns with and without Citibank
ret_with_citi = prices_with_citi.____.dot(weights_with_citi)
ret_without_citi = prices_without_citi.pct_change().____(____)
# Find the average 30-day rolling window volatility as the standard deviation
vol_with_citi = ret_with_citi.____.std().dropna().rename("With Citi")
vol_without_citi = ret_without_citi.rolling(30).____.dropna().rename("Without Citi")
# Combine two volatilities into one Pandas DataFrame
vol = pd.concat([____, ____], axis=1)
# Plot volatilities over time
vol.____().set_ylabel("Losses")
plt.show()