繪製標準化殘差的分佈
GARCH 模型會對「標準化殘差」的分佈做出假設。回顧一下,殘差是「預測報酬」與「平均報酬」之差;而標準化殘差則是用模型估計的波動度去除以殘差。
在這個練習中,你將從已配適的 GARCH 模型計算標準化殘差,接著把它的直方圖與標準常態分佈 normal_resid 一起繪出。
我們已用 S&P 500 的價格報酬資料定義並配適了一個 GARCH 模型,配適結果可由 gm_result 取得。此外,matplotlib 已以 plt 名稱預先載入。
本練習屬於課程
Python 中的 GARCH 模型
練習說明
- 取得模型估計的殘差,儲存為
gm_resid。 - 取得模型估計的波動度,儲存為
gm_std。 - 計算標準化殘差
gm_std_resid。 - 繪製
gm_std_resid的直方圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Obtain model estimated residuals and volatility
gm_resid = gm_result.____
gm_std = gm_result.____
# Calculate the standardized residuals
gm_std_resid = ____ /____
# Plot the histogram of the standardized residuals
plt.____(____, bins = 50,
facecolor = 'orange', label = 'Standardized residuals')
plt.____(normal_resid, bins = 50,
facecolor = 'tomato', label = 'Normal residuals')
plt.legend(loc = 'upper left')
plt.show()