18
$\begingroup$

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?

$\endgroup$

1 Answer 1

10
$\begingroup$

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)
$\endgroup$
13
  • 1
    $\begingroup$ 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. $\endgroup$
    – Vince
    May 9, 2013 at 0:03
  • 2
    $\begingroup$ 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? $\endgroup$ May 9, 2013 at 7:06
  • 2
    $\begingroup$ 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 $\endgroup$ May 9, 2013 at 7:17
  • 1
    $\begingroup$ 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. $\endgroup$
    – Vince
    May 9, 2013 at 12:56
  • 1
    $\begingroup$ 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... $\endgroup$
    – Vince
    May 9, 2013 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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