ACF 圖
如果 GARCH 模型表現良好,標準化殘差不應該呈現自我相關。在這個練習中,你會用 ACF 圖來偵測資料中的自我相關。
時間序列中兩個數值之間的相關係數稱為自我相關函數(ACF),而 ACF 圖則是不同落後期之間相關性的視覺化呈現。Python 的 statsmodels 套件提供了預先定義的函式,能讓你輕鬆產生 ACF 圖。
我們已用 S&P 500 報酬資料配適了一個 GARCH 模型,並計算出其標準化殘差,存放在 std_resid。matplotlib.pyplot 已以 plt 匯入。
本練習屬於課程
Python 中的 GARCH 模型
練習說明
- 從
statsmodels套件匯入產生 ACF 圖所需的模組。 - 繪製儲存在
std_resid的 GARCH 模型標準化殘差。 - 產生標準化殘差的 ACF 圖,並將信賴水準設為 0.05。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the Python module
from statsmodels.graphics.tsaplots import ____
# Plot the standardized residuals
plt.plot(____)
plt.title('Standardized Residuals')
plt.show()
# Generate ACF plot of the standardized residuals
____(std_resid, ____ = ____)
plt.show()