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 모델

연습해 봅시다!

Python으로 배우는 GARCH 모델

Preparing Video For Download...