应用 MA 模型
股票价格在买入价与卖出价之间来回跳动,会导致一阶负自相关,但在高于 1 的滞后上没有自相关。MA(1) 模型也会产生相同的 ACF 模式。因此,您将对上一个练习中的日内股票数据拟合一个 MA(1) 模型。
第一步是根据 intraday 中的价格计算逐分钟收益率,并绘制自相关函数。您应当观察到,该 ACF 看起来与 MA(1) 过程相似。然后,像对模拟数据所做的那样,将数据拟合为 MA(1) 并进行比较。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 从 statsmodels 导入
plot_acf和ARIMA模块 - 根据价格计算逐分钟收益率:
- 使用
.pct_change()方法计算收益率 - 使用 pandas 的
.dropna()方法删除第一行 NaN 的收益率
- 使用
- 绘制最长 60 分钟滞后的 ACF 图
- 将收益率数据拟合为 MA(1) 模型,并打印 MA(1) 参数
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import plot_acf and ARIMA modules from statsmodels
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.tsa.arima.model import ARIMA
# Compute returns from prices and drop the NaN
returns = intraday.___
returns = returns.___
# Plot ACF of returns with lags up to 60 minutes
plot_acf(___, ___)
plt.show()
# Fit the data to an MA(1) model
mod = ARIMA(___, order=(0,0,1))
res = mod.fit()
print(res.params[1])