PythonでのGARCHモデル実装

Pythonで学ぶGARCHモデル

Chelsea Yang

Data Science Instructor

Pythonの「arch」パッケージ

from arch import arch_model

1 Kevin Sheppard. (2019, March 28). bashtage/arch: Release 4.8.1 (Version 4.8.1). Zenodo. http://doi.org/10.5281/zenodo.2613877
Pythonで学ぶGARCHモデル

ワークフロー

GARCHモデルは次の3ステップで実装:

  1. モデルを指定
  2. モデルを適合
  3. 予測を作成
Pythonで学ぶGARCHモデル

モデル指定

【モデルの前提】

  • 分布: "normal"(既定)、"t""skewt"
  • 平均モデル: "constant"(既定)、"zero""AR"
  • 変動性モデル: "GARCH"(既定)、"ARCH""EGARCH"

 

basic_gm = arch_model(sp_data['Return'], p = 1, q = 1, 
                      mean = 'constant', vol = 'GARCH', dist = 'normal')
Pythonで学ぶGARCHモデル

モデル適合

nイテレーションごとに適合出力を表示:

gm_result = gm_model.fit(update_freq = 4)

モデル適合の進行

表示をオフにする:

gm_result = gm_model.fit(disp = 'off')
Pythonで学ぶGARCHモデル

適合結果:パラメータ

「最尤法」で推定

print(gm_result.params)
mu          0.077239
omega       0.039587
alpha[1]    0.167963
beta[1]     0.786467
Name: params, dtype: float64
Pythonで学ぶGARCHモデル

適合結果:サマリー

print(gm_result.summary())

モデル適合結果のサマリー

Pythonで学ぶGARCHモデル

適合結果:プロット

gm_result.plot()

モデル推定のプロット

Pythonで学ぶGARCHモデル

モデルの予測

# 5期先まで予測
gm_forecast = gm_result.forecast(horizon = 5)
# 分散予測の最終行を表示
print(gm_forecast.variance[-1:])
                 h.1       h.2       h.3       h.4       h.5
Date                                                        
2019-10-10  0.994079  0.988366  0.982913  0.977708  0.972741

「2019-10-10」の h.1:その日までのデータで行った1期先予測

Pythonで学ぶGARCHモデル

演習に進みましょう

Pythonで学ぶGARCHモデル

Preparing Video For Download...