Python 中的时间序列分析
Rob Reider
Adjunct Professor, NYU-Courant Consultant, Quantopian
从数据(模拟)估计参数
from statsmodels.tsa.arima_model import ARMA
mod = ARMA(data, order=(1,0))
result = mod.fit()
ARMA 已弃用,改用 ARIMA
from statsmodels.tsa.arima.model import ARIMA
mod = ARIMA(data, order=(1,0,0))
result = mod.fit()
对 ARMA,order=(p,q)
print(result.summary())

print(result.params)
array([-0.03605989, 0.90535667])
from statsmodels.graphics.tsaplots import plot_predict
fig, ax = plt.subplots()
data.plot(ax=ax)
plot_predict(result, start='2012-09-27', end='2012-10-06', alpha=0.05, ax=ax)
plt.show()
plot_predict() 的参数alpha=None 可去除置信区间ax=ax 可在同一坐标轴上绘制数据与预测
Python 中的时间序列分析