如何在 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 模型:

  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 模型

¡Vamos a practicar!

Python 中的 GARCH 模型

Preparing Video For Download...