Desperately seeking help: Out of Sample, recursive, one step ahead, GARCH volatility forecasting

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Econoforecast
Posts: 25
Joined: Sun Feb 19, 2017 1:25 pm

Desperately seeking help: Out of Sample, recursive, one step ahead, GARCH volatility forecasting

Postby Econoforecast » Sun Mar 19, 2017 9:23 pm

I wish to forecast volatility of stock index returns using GARCH models. This entails firstly, estimating using GARCH models in-sample, and then doing an out of sample forecast to obtain the residuals/GARCH variance series, which I will then use in a forecast evaluation with actual volatility (proxy is squared returns in this case). I wish to do recursive one step ahead forecasts whereby the coefficients are re-estimated and then stored, so that I can then make a GARCH variance series/extract the residuals and compare it with my squared returns.

I'm not sure what I'm doing wrong. Have used the code below. I tried running it via File>New>program. I had already generated the GARCH equation and saved it. Tried modifying the code by entering my own sample dates and GARCH equation, but nothing happened.

To be frank, not sure what to modify, and what to leave out. When I try running the code and setting 5 maximum errors, I get the following errors:

Code: Select all

%END is not defined or is an illegal command in "%END = "@LAST"   ".   is not defined or is an illegal command in "   ".   Syntax error in control statement in "FOR !I = 1  TO  5219-20+1-1 STEP 1".
To be clear, my in-sample period is from 5/31/1996 to 6/01/2006, whilst my out of sample period runs from 6/02/2006 yo 6/01/2016. Desperately need help and I'd be so grateful for any assistance on this.

Code: Select all

'run rolling regression ' set window size !window = 20 ' set step size !step = 1 ' get size of workfile !length = @obsrange ' declare equation for estimation equation garcheqn 'calculate number of rolls !nrolls = @floor((!length-!window)/!step) 'series to store forecast estimates series fcast '*EDITED: catching start and end points %start = "@FIRST" '@otod(@ifirst(ser))    %end = "@LAST"   '@otod(@ilast(ser))     'variable keeping track of how many rolls we've done !j=0 ' move sample !step obs at a time for !i = 1  to  !length-!window+1-!step step !step    !j=!j+1          ' set sample for estimation period             %first = @otod(@dtoo(%start))    %last = @otod(@dtoo(%start)+!i+!window-2)    smpl {%first} {%last}         ' estimate equation - where the equation is GARCH = C(6) + C(7)*RESID(-1)^2 + C(8)*GARCH(-1) garcheqn.ARCH RT_ASX200 C AR(1) AR(2) MA(1) MA(2)     ' 1-period-ahead forecast %1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point %1pere = @otod(@dtoo(%start)+!i+!window-1) 'end point       '*EDITED   if @dtoo(%end) < @dtoo(%1pere) then 'check whether the forecast end point is greater than the workfile end point       exitloop    endif        ' set smpl for forecasting period    smpl {%1pers} {%1pere}           ' forecast with command *forecast* (see also *fit*)    garcheqn.forecast(f=na) yf             ' set sampl to obtain the 4th period observation    smpl {%1pere} {%1pere}         ' store forecasts    fcast = yf next smpl @all show fcast.line d(noerr) yf
Have also attached the workfile
Attachments
Workfile recursive regression.zip
(1.64 MiB) Downloaded 579 times

EViews Matt
EViews Developer
Posts: 583
Joined: Thu Apr 25, 2013 7:48 pm

Re: Desperately seeking help: Out of Sample, recursive, one step ahead, GARCH volatility forecasting

Postby EViews Matt » Mon Mar 20, 2017 10:48 am

Hello,

With a fully patched version of EViews 9.5 I don't receive any errors.

Econoforecast
Posts: 25
Joined: Sun Feb 19, 2017 1:25 pm

Re: Desperately seeking help: Out of Sample, recursive, one step ahead, GARCH volatility forecasting

Postby Econoforecast » Mon Mar 20, 2017 2:00 pm

Hello,

With a fully patched version of EViews 9.5 I don't receive any errors.
Hi, Thanks a lot for replying. Much appreciated. I've just run the code on my friend's version and it seems to work. So I guess I'm almost done now, but I just need to clarify a few issues in terms of how well this script is written and modifying the script to fulfill my needs.

As mentioned before, I wish to do recursive one step ahead forecasts whereby the coefficients are re-estimated and then stored, so that I can then forecast a GARCH variance series and compare it with my squared returns.
QUESTION: Does this script re-estimate the co-efficients at every step?

Below is what I've done/Areas I need assistance if you can provide any. Please confirm if correct
1) As far as I can tell, I simply need to modify eq1 in the code with my own estimated equation right? Or do I just run the code without needing to do anything at all in the beginning?

2) To be clear, my full data set runs from 1996-2016. My in-sample period is from 5/31/1996 to 6/01/2006, whilst my out of sample period runs from 6/02/2006 to. 6/01/2016. How do I modify the code so that I can do an In-sample estimation from 1996-2016, and then make the forecast run from 2006-2016?

3) I will be using a GARCH equation rather than a Least Squares regression, is the code still viable for this? I changed the equation line with what I need and it still seems to run ok, so I assume it works for all different types of regressions without major alterations needed? Note, I also plan to run EGARCH, GJR, GARCH-M.

4) Perhaps most Importantly, how do I make it estimate my GARCH (which will obviously estimate the Mean and Variance), and then generate a recursive one step ahead variance series, rather than generating a series forecast of the mean which I think is what its doing right now?

To make it clearer, currently when I run it, I think it does the following: It estimates the full sample period from 1996-2016 and then generates a forecast series of the mean.

Whereas I need the code to: I need it to estimate the GARCH in-sample (and preferably generate an In-sample series from 1996-2016, but this is not essential). Then I need it to do recursive one step ahead forecasts of the variance and generate the series for this forecast.

Please confirm if my above analysis of what the code is doing above is correct.

Any help appreciated. Thanks.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Desperately seeking help: Out of Sample, recursive, one step ahead, GARCH volatility forecasting

Postby EViews Glenn » Tue Mar 28, 2017 10:07 am

A quick look indicates that both your estimation and forecast commands are inside the loop with appropriate sample statements preceding so you should be okay.

A simple way to verify is to interrupt your loop part way through and look at the estimated equation and the forecast series. You should see the appropriate samples.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest