Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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

I therefore use the ugarchfit command:


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?

share|improve this question
up vote 6 down vote accepted

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);
share|improve this answer
thanks for the up-vote. for completeness, with regard to the sample size and the n.roll argument, the number of points absolutely necessary is equal to the order p of the auto-regressive component, which in this case is 1: hence 2580-1, for the maximum allowable number of roll dates. – Veeken May 9 '13 at 0:03
Thanks a lot for your help, but: If I use out.sample doesn't that imply, that I do not take these values for fitting? But I want to use them for fitting. Also what is with the command fitted()? What is this command doing? – Stat Tistician May 9 '13 at 7:06
it is not really working, I get the error message (in german): nicht anwendbare Methode für 'sigma' auf Objekt der Klasse "c('uGARCHforecast', 'GARCHforecast', 'rGARCH')" angewendet – Stat Tistician May 9 '13 at 7:17
re: first comment: you asked specifically to use data that was used for the fit also to be used as input to the forecast. re: second comment: i get no such message. If you paste the code above directly after the code you provide, it should work. Though sigma() is a new method for objects of type ugarchforecast, so you might want to update via update.packages("rugarch"). Once you try this let me know if your third comment is still the case. the method sigma extracts the n.ahead conditional variance for each roll date; while the method fitted gives the conditional mean. – Veeken May 9 '13 at 12:56
hey man, my last suggestion is to try this on R 3.0, which is the version that i use. I actually ran it again to triple check, and the results are consistent with your request: one step ahead forecasts of the conditional variance using in sample data (one forecast for each date in the time series.) Note your conditional mean was modelled as ARFIMA(0,0,0), which is why fitted(forecast) is 0 for each date, and why residuals(modelfit) - mydata[,1] = $\mathbf{0}$. Good luck... – Veeken May 9 '13 at 15:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.