開始使用免費開始

比較 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()
編輯並執行程式碼