GARCH Models in R
Kris Boudt
Professor of finance and econometrics
The normal GARCH model
$$ 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} $$
library(rugarch) citation("rugarch")
To cite the rugarch package, please use: Alexios Ghalanos (2018). rugarch: Univariate GARCH models.R package version 1.4-0.
Three steps:
ugarchspec()
: Specify which GARCH model you want to use (mean $\mu_t$, variance $\sigma^2_t$, distribution of $e_t$)
ugarchfit()
: Estimate the GARCH model on your time series with returns $R_1,...,R_T$.
ugarchforecast()
: Use the estimated GARCH model to make volatility predictions for $R_{T+1}$,...
ugarchspec()
specifies which GARCH model you want to use.
garchspec <- ugarchspec(mean.model = list(armaOrder = c(0,0)),
variance.model = list(model = "sGARCH"),
distribution.model = "norm")
ugarchfit()
estimates the GARCH model.
garchfit <- ugarchfit(data = sp500ret, spec = garchspec)
ugarchforecast()
forecasts the volatility of the future returns.
garchforecast <- ugarchforecast(fitORspec = garchfit, n.ahead = 5)
ugarchfit
yields an object that contains all the results related to the estimation of the garch model. coef
, uncvar
, fitted
and sigma
: # Coefficients
garchcoef <- coef(garchfit)
# Unconditional variance
garchuncvar <- uncvariance(garchfit)
# Predicted mean
garchmean <- fitted(garchfit)
# Predicted volatilities
garchvol <- sigma(garchfit)
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
garchvol <- sigma(garchfit)
plot(garchvol)
tail(garchvol, 1)
2017-12-29 0.004862908
What about the volatility for the days following the end of the time series?
sigma()
method to the ugarchforecast
object gives the volatility forecasts: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
Applying the fitted()
method to the ugarchforecast
object gives the mean forecasts:
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
A portfolio that invests a percentage $w$ in a risky asset (with volatility $\sigma_t$) and keeps $1-w$ on a risk-free bank deposit account has volatility equal to
$$ \sigma_p = w \sigma_t$$
How to set $w$? One approach is volatility targeting: $w$ is such that the predicted annualized portfolio volatility equals a target level, say 5%. Then:
$$ w^* = 0.05 /\sigma_t $$
Since GARCH volatilities change, the optimal weight changes as well.
GARCH Models in R