Skip to content
All library documents

Plotting GARCH(1,1) Volatility Forecasts with Training Data in R

Article Quant Q&A · Author: Ben

Summary

The document shows how to plot fitted conditional volatility together with forecasts from a GARCH(1,1) model in R. Its example uses the fGarch package to specify and simulate a normally distributed GARCH process, fit the model, and predict future conditional standard deviations. It then combines the fitted conditional standard deviations and forecast values in a time series and draws them in different colors to distinguish historical fit from the forecast.

The example is a practical plotting template, not a discussion of forecast accuracy or financial interpretation. It uses simulated data and fixed model parameters, so it does not establish how the approach performs on real market data. The answer also notes that the predicted series can be plotted instead of predicted conditional standard deviation through an option in the prediction call.

Key ideas

  • The example uses fGarch to simulate, fit, and forecast a GARCH(1,1) model.
  • Fitted conditional standard deviations and forecast standard deviations are combined in one time series.
  • The plot uses separate colors to distinguish the fitted history from the forecast horizon.
  • The demonstration uses simulated data and does not assess forecasting performance on real assets.
  • A prediction option can display the predicted series instead of conditional standard deviation.

Tags

Full text
# GARCH(1,1) forecast plot in R with training data


# GARCH(1,1) forecast plot in R with training data












I've fit a GARCH(1,1) model in R and would like to create a plot similar to the one in this question: Is this the correct way to forecast stock price volatility using GARCH

Could someone direct me to a guide or literature that I could use to achieve this?

## Answer by Alba (score 1)

https://quant.stackexchange.com/a/54787

Here's a reproducible example using the package `fGarch`, I hope you can adapt it to your situation:

```
library("fGarch")

# Create specification for GARCH(1, 1)
spec <- garchSpec(model = list(omega = 0.05, alpha =  0.1, beta = 0.75), cond.dist = "norm")

# Simulate the model with n = 1000
sim <- garchSim(spec, n = 1000)

# Fit a GARCH (1, 1)
fit <- garchFit(formula = ~ garch(1, 1), data = sim, include.mean = F)

# Predict 40 steps ahead
pred <- predict(fit, n.ahead = 40)

# Concatenate the fitted model with the prediction, transform to time series
dat <- as.ts(c(sqrt(fit@h.t), pred = pred$standardDeviation))

# Create the plot
plot(window(dat, start = start(dat), end = 1000), col = "blue",
     xlim = range(time(dat)), ylim = range(dat),
     ylab = "Conditional SD", main = "Prediction based on GARCH model")

par(new=TRUE)

plot(window(dat, start = 1000), col = "red", axes = F, xlab = "", ylab = "", xlim = range(time(dat)), ylim = range(dat))
```

A thank you to the writer of the answer in this thread, I used it to get the graphics right.

Also note that you can create a plot of the predicted series, rather than the predicted conditional standard deviation, by using the `plot = T` argument in the call to `predict`.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.