rugarch 包

在 R 中构建 GARCH 模型

Kris Boudt

Professor of finance and econometrics

常均值的正态 GARCH(1,1)

正态 GARCH 模型

$$ R_t = \mu + e_t $$ $$ e_t \sim N(0, \sigma^2_t) $$ $$ \sigma^2_t = \omega + \alpha e^2_{t-1} + \beta \sigma^2_{t-1} $$

  • 四个参数:$\mu, \omega, \alpha, \beta$。
  • 极大似然估计:寻找使该 GARCH 模型最可能生成观测收益序列的参数值。
在 R 中构建 GARCH 模型

Alexios Ghalanos

library(rugarch)
citation("rugarch")

引用 rugarch 包请使用: Alexios Ghalanos (2018). rugarch: Univariate GARCH models.R package version 1.4-0.
在 R 中构建 GARCH 模型

流程

  • 三个步骤:

    • ugarchspec(): 指定要使用的 GARCH 模型(均值 $\mu_t$、方差 $\sigma^2_t$、$e_t$ 的分布)

      • ugarchfit(): 在收益序列 $R_1,...,R_T$ 上估计 GARCH 模型。

      • ugarchforecast(): 用估计的模型预测 $R_{T+1}$ 等的波动率。

在 R 中构建 GARCH 模型

R 中的流程

ugarchspec() 用于指定要使用的 GARCH 模型。

garchspec <- ugarchspec(mean.model = list(armaOrder = c(0,0)),
                           variance.model = list(model = "sGARCH"),
                           distribution.model = "norm")

ugarchfit() 估计 GARCH 模型。

garchfit <- ugarchfit(data = sp500ret, spec = garchspec)

ugarchforecast() 预测未来收益的波动率。

garchforecast <- ugarchforecast(fitORspec = garchfit, n.ahead = 5)
在 R 中构建 GARCH 模型

ugarchfit 对象

  • ugarchfit 产生一个对象,包含 GARCH 模型估计的全部结果。
  • 方法 coefuncvarfittedsigma
# 系数
garchcoef <- coef(garchfit)
# 无条件方差
garchuncvar <- uncvariance(garchfit)
# 预测均值
garchmean <- fitted(garchfit) 
# 预测波动率
garchvol <- sigma(garchfit)

在 R 中构建 GARCH 模型

标普500日收益的 GARCH 系数

print(garchcoef)
          mu        omega       alpha1        beta1 
5.728020e-04 1.220515e-06 7.792031e-02 9.111455e-01 

$$ R_{t} = 5.7 \times 10^{-4} + e_{t} $$ $$ e_{t} \sim N(0, \hat{\sigma}^{2}_{t}) $$ $$ \hat{\sigma}^{2}_{t} = 1.2 \times 10^{-6} + 0.08 e^{2}_{t-1} + 0.91 \hat{\sigma}^{2}_{t-1} $$

sqrt(garchuncvar)
0.01056519
在 R 中构建 GARCH 模型

估计的波动率

garchvol <- sigma(garchfit)
plot(garchvol)

在 R 中构建 GARCH 模型

未来波动率如何?

tail(garchvol, 1)
2017-12-29 0.004862908

那时间序列结束后的几天波动率如何?

在 R 中构建 GARCH 模型

预测 h 日后的波动率

  • ugarchforecast 对象应用 sigma() 可得到波动率预测:
sigma(garchforecast)
      2017-12-29
T+1  0.005034754
T+2  0.005127582
T+3  0.005217770
T+4  0.005305465
T+5  0.005390797
在 R 中构建 GARCH 模型

预测 h 日后的波动率

ugarchforecast 对象应用 fitted() 可得到均值预测:

fitted(garchforecast)
      2017-12-29
T+1  0.000572802
T+2  0.000572802
T+3  0.000572802
T+4  0.000572802
T+5  0.000572802
在 R 中构建 GARCH 模型

战术资产配置的应用

一个组合将比例 $w$ 投资于风险资产(波动率为 $\sigma_t$),其余 $1-w$ 存无风险账户,其波动率为

$$ \sigma_p = w \sigma_t$$

如何设定 $w$?一种方法是波动率目标:令预测的年化组合波动率等于目标(如 5%)。则:

$$ w^* = 0.05 /\sigma_t $$

由于 GARCH 波动率会变,最优权重也会变。

在 R 中构建 GARCH 模型

来玩转 rugarch!

在 R 中构建 GARCH 模型

Preparing Video For Download...