library(fGarch)
library(tseries)
data(EuStockMarkets) #load data
plot( EuStockMarkets[,"DAX"] , ylab = "Price", main = "Time Series of Closing Price of DAX")
#first differencing on the closing price to get returns
dax <- diff(log(EuStockMarkets))[,"DAX"]
#preview latest 20 days returns
print( tail(dax, 20) )
## [1] 0.0037622676 -0.0003217412 -0.0167942368 -0.0061509827 -0.0005362285
## [6] -0.0313150592 0.0022470827 -0.0066312038 0.0132238036 -0.0076720025
## [11] -0.0149217633 -0.0096893845 -0.0183408812 -0.0155528317 0.0126187588
## [16] -0.0249390115 -0.0325073453 0.0189573098 -0.0059411996 0.0219221523
#plot the returns time series
plot(dax, xlab = "Time (year)", main = "Time Series of Returns of DAX")
log <- capture.output({ #ignore this function (To suppress unnecessary message output ##
fit <- garchFit(~garch(1, 1), data = dax)
})
summary(fit)
Title:
GARCH Modelling
Call:
garchFit(formula = ~garch(1, 1), data = dax)
Mean and Variance Equation:
data ~ garch(1, 1)
<environment: 0x00000000176aa3a0>
[data = dax]
Conditional Distribution:
norm
Coefficient(s):
mu omega alpha1 beta1
6.5351e-04 4.7543e-06 6.8417e-02 8.8761e-01
Std. Errors:
based on Hessian
Error Analysis:
Estimate Std. Error t value Pr(>|t|)
mu 6.535e-04 2.158e-04 3.029 0.00245 **
omega 4.754e-06 1.264e-06 3.760 0.00017 ***
alpha1 6.842e-02 1.478e-02 4.630 3.66e-06 ***
beta1 8.876e-01 2.356e-02 37.677 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Log Likelihood:
5966.214 normalized: 3.209368
Description:
Fri Apr 14 23:51:32 2017 by user: User
Standardised Residuals Tests:
Statistic p-Value
Jarque-Bera Test R Chi^2 13380.69 0
Shapiro-Wilk Test R W 0.9477474 0
Ljung-Box Test R Q(10) 3.195816 0.9764329
Ljung-Box Test R Q(15) 10.13427 0.8112099
Ljung-Box Test R Q(20) 12.80196 0.8857182
Ljung-Box Test R^2 Q(10) 0.893265 0.9998977
Ljung-Box Test R^2 Q(15) 1.329651 0.9999981
Ljung-Box Test R^2 Q(20) 1.756904 1
LM Arch Test R TR^2 1.08588 0.9999776
Information Criterion Statistics:
AIC BIC SIC HQIC
-6.414432 -6.402538 -6.414441 -6.410049
# predict(fit, n.ahead = 10,plot = T)
#1-day ahead volatility forecast
sd1 <- predict(fit, n.ahead = 30,plot = T)[1,3]
print(sd1)
## [1] 0.01526939
Therefore, the 1-day ahead forecast volatility is 0.0152694.
sd2 <- sd(dax)
print(sd2)
## [1] 0.01030084
The sample standard deviation of returns is 0.0103008, which is lower than the 1-day ahead forecast volatility, 0.0152694.