观察波动率聚集
波动率聚集在金融市场数据中很常见,这会给时间序列建模带来挑战。
在本练习中,您将熟悉 S&P 500 的日度价格数据。您将把日度收益计算为价格的百分比变化,绘制结果,并观察其随时间的变化特征。
历史的 S&P 500 日度价格数据已预加载到 sp_price 中。
本练习是课程的一部分
Python 中的 GARCH 模型
练习说明
- 将日度收益计算为价格的百分比变化,并将其保存到 DataFrame
sp_price的新列Return中。 - 打印最后 10 行以查看数据。
- 绘制
Return列,并观察是否存在波动率聚集的迹象。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Calculate daily returns as percentage price changes
sp_price['____'] = 100 * (sp_price['Close'].____())
# View the data
print(sp_price.____(____))
# plot the data
plt.plot(sp_price['____'], color = 'tomato', label = 'Daily Returns')
plt.legend(loc='upper right')
plt.show()