开始使用免费开始使用

计算波动率

在本练习中,您将练习如何在 Python 中计算并换算价格收益的波动率。

首先,您将把日度波动率计算为价格收益的标准差。然后把日度波动率换算为月度和年度波动率。

S&P 500 的时间序列已预加载到 sp_data,百分比价格收益存放在 'Return' 列中。

本练习是课程的一部分

Python 中的 GARCH 模型

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Plot the price returns
plt.plot(sp_data['____'], color = 'orange')
plt.show()

# Calculate daily std of returns
std_daily = sp_data['____'].____()
print('Daily volatility: ', '{:.2f}%'.format(std_daily))
编辑并运行代码