Load the EuStockMarkets (DAX Index) data

library(fGarch)
library(tseries)

data(EuStockMarkets) #load data

Looking at the DAX Index - Closing Price & Returns

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")

Fit a GARCH(1,1) model on the returns

log <- capture.output({  #ignore this function (To suppress unnecessary message output ##
      
   fit <- garchFit(~garch(1, 1), data = dax) 
      
}) 

Predict 30-days ahead returns and volatilities

# 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.

Calculating volatility using sample standard deviation

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.