Skip to content
All library documents

Remove Initial Missing Returns Before Rolling GARCH Backtests

Article Quant Q&A · Author: Pelumi

Summary

This note diagnoses a warning from a rolling GARCH estimation in R. The example computes returns from SPY closing prices with `ROC`, then passes them to `ugarchroll` for repeated model estimation. The key issue is that the first return is missing because a change cannot be calculated without a prior price.

The suggested fix is to calculate returns without padding the missing initial observation, so the input series begins with a valid return. The displayed heads of the series show how this removes the leading NA. This is a data-preparation fix for the specific warning context; the note does not establish that every non-convergence warning has the same cause or address other solver and model issues.

Key ideas

  • The first return from a price series is undefined when no earlier observation is available.
  • A leading missing value can interfere with rolling GARCH estimation.
  • Removing the padded initial observation is the proposed remedy in this example.
  • Other causes of non-convergence are outside the note’s discussion.

Tags

Full text
# Error message when backtesting GARCH in R


# Error message when backtesting GARCH in R












I am trying to backtest my ARCH model using `ugarchroll` from `rugarch` package in R, but I am getting this warning message

```
"Warning message: In .rollfdensity(spec = spec, data = data, n.ahead = n.ahead, forecast.length = forecast.length, :

non-converged estimation windows present...resubsmit object with different solver parameters."
```

This is my code

```
library(quantmod)
library(rugarch)

getSymbols("SPY")
rets=ROC(SPY$SPY.Close)
tgarch = ugarchspec(mean.model = list(armaOrder = c(1, 1)), 
                    variance.model = list(model = "sGARCH"),
                    distribution.model = "std")
garchroll<-ugarchroll(tgarch, data = rets,n.start =500, 
                      refit.window="window", refit.every =200)
```

## Answer by skoestlmeier (score 2, accepted)

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

The error arises because the first element of `rets` is `NA` (which is expected behavior as `ROC` calculates the rate of change of a series, but a previous value prior to the first element is naturally not available).

To avoid this, add the optional argument `na.pad = FALSE`, i.e. `rets = ROC(SPY$SPY.Close, na.pad = FALSE)`:

```
> rets=ROC(SPY$SPY.Close)
> head(rets)
               SPY.Close
2007-01-03            NA
2007-01-04  0.0021198638
2007-01-05 -0.0080082993
2007-01-08  0.0046144192
2007-01-09 -0.0008502445
2007-01-10  0.0033260425
```

```
> rets = ROC(SPY$SPY.Close, na.pad = FALSE)
> head(rets)
               SPY.Close
2007-01-04  0.0021198638
2007-01-05 -0.0080082993
2007-01-08  0.0046144192
2007-01-09 -0.0008502445
2007-01-10  0.0033260425
2007-01-11  0.0043708988
```

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.