Skip to content
All library documents

Rolling In-Sample GARCH Forecasts with rugarch

Article Quant Q&A · Author: Stat Tistician

Summary

The document explains how to obtain one-step-ahead conditional mean and volatility forecasts across a time series after fitting an sGARCH model with rugarch. A standard call to the forecast function returns a forecast at the end of the fitted sample, which does not provide the desired sequence of historical rolling forecasts.

The proposed approach uses the forecast function's rolling parameter and sets the out-of-sample portion to cover the observations to be forecast. It also extracts the fitted model specification, fixes its parameters at the estimates from the original fit, and supplies the data slice used for the rolling calculation. The resulting forecast object can provide both conditional volatility and fitted conditional mean values. This method holds parameters fixed while advancing the forecast origin; it is not a sequence of refits, so it does not represent forecasts from a model re-estimated at each date. The example uses a specific sample length, which must be adapted to the data.

Key ideas

  • The default one-step-ahead forecast reports only the forecast at the end of the fitted sample.
  • The rolling forecast parameter controls how many forecast origins are produced.
  • The out-of-sample setting allows in-sample observations to be treated as forecast targets.
  • Fixing the original fit's coefficients keeps the model parameters constant across forecast origins.
  • The forecast object supplies both conditional mean and conditional volatility series.

Tags

Full text
# Forecasting using rugarch package


# Forecasting using rugarch package












I want to do one step ahead in-sample forecasts. My data can be found here. This is just a data frame with the date as the rownames.

I specify my model and do the fit and show the plots with

```
library(rugarch)
model<-ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)), 
mean.model = list(armaOrder = c(0, 0), include.mean = FALSE), 
distribution.model = "norm")

modelfit<-ugarchfit(spec=model,data=mydata)
plot(modelfit)
```

Now I want to do one-step-ahead in sample forecasts of my cond. mean and cond. volatility.

I therefore use the ugarchfit command:

```
ugarchforecast(modelfit,n.ahead=1,data=mydata)
```

But this is only one value for the last date. So I want to have this for every data starting from the beginning and up to my final values. These should be 1-step-ahead forecasts which use the specified model parameters and my data. How can I get this?

## Answer by Vince (score 10, accepted)

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

You want to set the parameter `n.roll` to the number of `n.ahead`, `n.roll` rolling forecasts you want. (The `n.ahead` parameter controls how many steps ahead you want to forecast for each roll date.) Thus by setting `n.roll` to a number almost equal to your sample size, and critically setting the `out.sample` parameter almost equal to your sample size, you're telling the method to take a specified fit and treat the in sample data as out of sample data, and thereby roll the forecast `n.roll` times, `n.ahead` times forward each time.

This will do it:

```
spec = getspec(modelfit);
setfixed(spec) <- as.list(coef(modelfit));
forecast = ugarchforecast(spec, n.ahead = 1, n.roll = 2579, data = mydata[1:2580, ,drop=FALSE], out.sample = 2579);
sigma(forecast);
fitted(forecast)
```

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.