Application of GARCH models in R – Part I
You probably heard about the GRACH models and its application to forecast volatility for financial stock prices. In this post I don’t want to go deeply about the concept of the GARCH models, instead I want to show you an application of using these models to forecast volatility.
This is the first post of a GARCH
application series, for the future we explain more about the more advanced
application and how to interpret the result.
The general model of GARCH (Generalized
Autoregressive Conditional Heteroskedasticity) is GARCH(p, q),
which p and q are the number of lag variances and the
number of lag residual errors respectively.
If we define p=0 i.e. GARCH(0, q)
is equivalent to an ARCH(q) model. In the ARCH(q) process
the conditional variance is specified as a linear function of past sample
variances only, whereas the GARCH(p, q) process allows lagged
conditional variances to enter as well. This corresponds to some sort of
adaptive learning mechanism.
GARCH(1,1):
and
ARCH(1):
If we need to have higher
level lags in the model for example GARCH(4,1) the model will defined as
follows:
In these models 𝟂 is constant and we need to estimate 𝟂, 𝞪 and 𝞫.
In the
following code I used fGarch package for estimating the model coefficients
for SP500 daily returns for the period between "2009-01-01"
and most up to date price data.
garch01@fit$coef
library(quantmod)
|
library(fGarch)
|
Symb = '^GSPC'
|
# download the SP500 adjusted
close price from yahoo finance
|
P = getSymbols(Symbols = Symb, src = "yahoo", from =c("2009-01-01") ,
|
to = Sys.Date(), auto.assign = F,periodicity = "daily")[,6]
|
log_return = diff(log(P))*100
|
Zero_mean_return= log_return - mean(as.vector(log_return),na.rm = TRUE)
|
# Garch modeling: ARCH(1)
|
garch01=garchFit(formula = ~garch(1,0), data =na.omit(Zero_mean_return),
|
include.mean = FALSE)
|
names(garch01@fit)
[1] "par" "objective" "convergence"
"iterations" "evaluations"
"message"
[7] "value" "coef" "llh" "hessian" "ics" "series"
[13] "params" "cvar" "se.coef" "tval" "matcoef"
Now we can find the estimated the coefficients
by this command:
|
omega alpha1
0.7990782 0.2747121
Remember the ARCH(1) model was.
Now lets model the volatility with more complex model i.e. GARCH(1,1) with skew student-t conditional distribution.
According to the GARCH(1,1) we just need the last volatility and return in order to forecast volatility for the next period. You can see the estimated coefficients for GARCH(1,1) with skew student_t conditionla distribution as follows.
Remember the ARCH(1) model was.
Now let us plot results.
By plotting the estimated model you will have 13 different plot options that you can use
for your analysis.
> plot(garch01)
Make a plot selection (or 0 to exit):
1: Time Series
SP500 Returns 2009-01-01 to 2019-11-01
Now lets model the volatility with more complex model i.e. GARCH(1,1) with skew student-t conditional distribution.
garch11_s_t=garchFit(
formula = ~garch(1,1),data=na.omit(Zero_mean_return),
|
include.mean = FALSE, cond.dist = "sstd",trace= F)
|
garch11_s_t@fit$coef
|
garch11_s_t@fit$llh
|
plot(garch11_s_t)
|
According to the GARCH(1,1) we just need the last volatility and return in order to forecast volatility for the next period. You can see the estimated coefficients for GARCH(1,1) with skew student_t conditionla distribution as follows.
omega = 0.01883026
alpha1 = 0.14946961
beta1 = 0.84392795
skew = 0.8884789
shape = 5.32634804
Comments
Post a Comment