How to implement GARCH models in Python

GARCH Models in Python

Chelsea Yang

Data Science Instructor

Python "arch" package

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
GARCH Models in Python

Workflow

Develop a GARCH model in three steps:

  1. Specify the model
  2. Fit the model
  3. Make a forecast
GARCH Models in Python

Model specification

Model assumptions:

  • Distribution: "normal" (default), "t", "skewt"
  • Mean model: "constant" (default), "zero", "AR"
  • Volatility model: "GARCH" (default), "ARCH", "EGARCH"

 

basic_gm = arch_model(sp_data['Return'], p = 1, q = 1, 
                      mean = 'constant', vol = 'GARCH', dist = 'normal')
GARCH Models in Python

Model fitting

Display model fitting output after every n iterations:

gm_result = gm_model.fit(update_freq = 4)

Model fitting process

Turn off the display:

gm_result = gm_model.fit(disp = 'off')
GARCH Models in Python

Fitted results: parameters

Estimated by "maximum likelihood method"

print(gm_result.params)
mu          0.077239
omega       0.039587
alpha[1]    0.167963
beta[1]     0.786467
Name: params, dtype: float64
GARCH Models in Python

Fitted results: summary

print(gm_result.summary())

Model fitting result summary

GARCH Models in Python

Fitted results: plots

gm_result.plot()

Plots of model estimations

GARCH Models in Python

Model forecasting

# Make 5-period ahead forecast
gm_forecast = gm_result.forecast(horizon = 5)
# Print out the last row of variance forecast
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

h.1 in row "2019-10-10": 1-step ahead forecast made using data up to and including that date

GARCH Models in Python

Let's practice!

GARCH Models in Python

Preparing Video For Download...