開始使用免費開始

AR(1) 與 MA(無窮) 的等價性

為了更了解 MA 模型與 AR 模型之間的關係,你將示範:在適當參數下,AR(1) 模型等同於 MA(\(\small \infty\)) 模型。

你將模擬一個 MA 模型,其參數為 $\small 0.8, 0.8^2, 0.8^3, \ldots $,並取較大的落後期數(30),然後展示它與 AR(1) 模型(\(\small \phi=0.8\))具有相同的自相關函數(Autocorrelation Function)。

注意:要把數字 x 提升為指數 n 次方,請使用 x**n 的格式。

本練習屬於課程

Python 中的時間序列分析

檢視課程

練習說明

  • 從 statsmodels 匯入用於模擬資料與繪製 ACF 的模組。
  • 使用串列生成式建立一組「指數式」衰減的 MA 參數:$\small 1, 0.8, 0.8^2, 0.8^3, \ldots$。
  • 模擬 MA(30) 模型的 5000 筆觀測值。
  • 繪製此模擬序列的 ACF。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# import the modules for simulating data and plotting the ACF
from statsmodels.tsa.arima_process import ArmaProcess
from statsmodels.graphics.tsaplots import plot_acf

# Build a list MA parameters
ma = [___ for i in range(30)]

# Simulate the MA(30) model
ar = np.array([1])
AR_object = ArmaProcess(ar, ___)
simulated_data = ___.generate_sample(nsample=5000)

# Plot the ACF
plot_acf(___, lags=30)
plt.show()
編輯並執行程式碼