开始使用免费开始使用

比较 AR 模型与随机游走

有时很难区分一个轻微均值回复的时间序列与完全不均值回复(如随机游走)的序列。您将把上一个练习中的轻微均值回复的利率序列,与一个具有相同观测数的模拟随机游走的 ACF 进行比较。

将这两个序列的自相关函数并排绘图时,您应该会注意到它们看起来非常相似。

本练习是课程的一部分

Python 中的时间序列分析

查看课程

练习说明

  • statsmodels 模块中导入 plot_acf 函数
  • 为两个子图创建两个坐标轴
  • 在上方子图中绘制利率序列 interest_rate_data 的 12 个滞后的自相关函数
  • 在下方子图中绘制序列 simulated_data 的 12 个滞后的自相关函数

交互式实操练习

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

# Import the plot_acf module from statsmodels
from statsmodels.graphics.tsaplots import plot_acf

# Plot the interest rate series and the simulated random walk series side-by-side
fig, axes = plt.subplots(2,1)

# Plot the autocorrelation of the interest rate series in the top plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[0])

# Plot the autocorrelation of the simulated random walk series in the bottom plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[1])

# Label axes
axes[0].set_title("Interest Rate Data")
axes[1].set_title("Simulated Random Walk Data")
plt.show()
编辑并运行代码