时序分析(8) -- GARCH(p,q)模型

时序分析(8)

GARCH(p,q)模型

    上篇文章我们探讨了ARCH模型对时序数据的波动性进行建模和预测,本篇文章介绍GARCH模型。 首先我们介绍GARCH模型的基本概念:

Generalized Autoregressive Conditionally Heteroskedastic Models - GARCH(p,q)

简单来说,GARCH模型就是ARMA模型应用在时序的方差上,它包含一个自回归项和一个移动平均项.

如果时序数据 { y t } \{y_t\} {yt}可以表示为
y t = σ t w t y_t=\sigma_t w_t yt=σtwt
其中 { w t } \{w_t\} {wt}是高斯白噪声,均值为0,方差为1,这里 σ t \sigma_t σt
σ t 2 = α 0 + ∑ i = 1 q α i y t − i 2 + ∑ j = 1 p β j σ t − j 2 \sigma_t^2=\alpha_0+\sum_{i=1}^{q}\alpha_iy_{t-i}^2+\sum_{j=1}^{p}\beta_j\sigma_{t-j}^2 σt2=α0+i=1qαiyti2+j=1pβjσtj2
让我们先从简单做起,考虑GARCH(1,1)模型
y t = σ t w t y_t=\sigma_tw_t yt=σtwt
σ t 2 = α 0 + α 1 y t − 1 2 + β 1 σ t − 1 2 \sigma_t^2=\alpha_0+\alpha_1y_{t-1}^2+\beta_1\sigma_{t-1}^2 σt2=α0+α1yt12+β1σt12
注意:这里 α 1 + β 1 < 1 \alpha_1+\beta_1 \lt 1 α1+β1<1,否则时序将会不稳定。

导入python包和数据

如前一样

我们先模拟一个GARCH(1,1)时序

# Simulating a GARCH(1, 1) process
np.random.seed(2)

a0 = 0.2
a1 = 0.5
b1 = 0.3

n = 10000
w = np.random.normal(size=n)
y = np.zeros_like(w)
sigsq = np.zeros_like(w)

for i in range(1, n):
    sigsq[i] = a0 + a1*(y[i-1]**2) + b1*sigsq[i-1]
   y[i] = w[i] * np.sqrt(sigsq[i])
_ = tsplot(y, lags=30)

在这里插入图片描述
看上去很类似一个白噪声过程。

模拟时序的平方

tsplot(y*y, lags=30)

在这里插入图片描述
从ACF,PACF中显示出显著自相关性,我们需要AR项和MA项。
我们尝试是否可以通过模型拟合来得到模拟的参数。

# Fit a GARCH(1, 1) model to our simulated EPS series
# We use the arch_model function from the ARCH package
am = arch_model(y)
res = am.fit(update_freq=5)
print(res.summary())

在这里插入图片描述
我们较好地恢复了参数。

模拟数据GARCH残差plot

_ = tsplot(res.resid, lags=30)

在这里插入图片描述

以GARCH建模国内股票收益率

步骤如下:

  1. 以ARIMA模型迭代得到最佳参数。
  2. 以ARIMA模型所得到地具备最低AIC的参数来选择GARCH模型。
  3. 使GARCH模型适配时序数据。
  4. 检查模型残差和残差平方的自相关性。
def _get_best_model(TS):
    best_aic = np.inf
    best_order = None
    best_mdl = None
    pq_rng = range(5) # [0,1,2,3,4]
    d_rng = range(2) # [0,1]
    for i in pq_rng:
        for d in d_rng:
            for j in pq_rng:
                try:
                    tmp_mdl = smt.ARIMA(TS, order=(i,d,j)).fit(
                                       method='mle', trend='nc'
                              )
                    tmp_aic = tmp_mdl.aic
                    if tmp_aic < best_aic:
                        best_aic = tmp_aic
                        best_order = (i, d, j)
                        best_mdl = tmp_mdl
                 except: continue
                 
    print('aic: {:6.5f} | order: {}'.format(best_aic, best_order))
    return best_aic, best_order, best_mdl
# Notice I've selected a specific time period to run this analysis
TS = indexs_logret['国内股票']
res_tup = _get_best_model(TS)

aic: -6601.86081 | order: (3, 0, 2)
得到p,d,q = 3,0,2
残差Plot

_ = tsplot(res_tup[2].resid, lags=30)

在这里插入图片描述
残差并非正态分布。

残差平方

_ = tsplot(res_tup[2].resid**2, lags=30)

在这里插入图片描述
残差平方显示较强的自相关性

拟合GARCH模型
order = [3,0,2]
p_ = order[0]
o_ = order[1]
q_ = order[2]

# Using student T distribution usually provides better fit
am = arch_model(10*TS, p=p_, o=o_, q=q_, dist='StudentsT')
res = am.fit(update_freq=5, disp='off')
print(res.summary())

在这里插入图片描述
GARCH模型残差Plot

_ = tsplot(res.resid, lags=30)

在这里插入图片描述
残差平方自相关性依然显著,说明模型拟合不是很成功。

香港股票收益率GARCH拟合

过程同上
aic: -1958.01617 | order: (2, 0, 2)
得到p,d,q=2,0,2
残差Plot

残差平方Plot
在这里插入图片描述
拟合GARCH模型

order = [2,0,2]
p_ = order[0]
o_ = order[1]
q_ = order[2]
# Using student T distribution usually provides better fit
am = arch_model(10*TS, p=p_, o=o_, q=q_, dist='StudentsT')
res = am.fit(update_freq=5, disp='off')
print(res.summary())

在这里插入图片描述
GARCH残差Plot
在这里插入图片描述
拟合效果优于国内股票

总结

    本文展示了采用Python语言为指数时序数据进行GARCH建模,并介绍了GARCH模型的基本概念。

  • 10
    点赞
  • 138
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值