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?

  • Veeken

    Veeken Correct answer

    8 years ago

    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)
    

    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.

    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?

    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

    also, your ugarchforecast is not working, if you look at the output, you will see, that it just gives one forecast? So there should be like 2579 forecasts, but not just one?

    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.

    thanks for your response. I updated my package and I still get the error? Also still, the forecast is only one value?

    I have R version 2.15.1 2012-06-22 I really focused on copying everything correctly?

    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...

    mh @Veeken well, a big thanks to you for your help anyway!

    ok, one more question: You are right, I have no mean equation, so I can write my model as r_t= sigma_t * epsilon_t so the r_t are my data and the sigma_t are the sigma() values. Now my question is: What are the residuals() values? Are these the epsilon_t? Or the sigma()*epsilon_t values? Since you mentioned, that residuals-data = 0, I guess the residuals are equal to the sigma()*epsilon_t values? Is this correct?

    I have further questions @Veeken, could I invite you to a chat?

    Hi, the residuals are the epsilon_t. the epsilon_t are equal to sigma_t*z_t where z_t is assumed to be iid standard normal (in this case.) if you look at mydata[,1]/sigma(modelfit) and take the mean and sd you will see proof of this. residuals(modelfit)-mydata[,1]=0 because you have no conditional mean component, thus when you fit via modelfit<-ugarchfit(spec=model,data=mydata), the MLE estimates for the coefficients for sigma_t reproduced the data exactly in keeping with the normality assumption for z_t and in turn conditional normality for the epsilon_t, AKA, the residuals.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used