Page 1 of 1

In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Mon Mar 22, 2021 3:21 am
by saraphdnz
Hello there,

I am trying to forecast the volatility as conditional standard deviation via the TGARCH model and want to use the extended window to obtain the in-sample forecast. I have data from Jan1960 till Mar2012, and I want to use a sample from Jan1960 - Dec1993 for estimating TGARCH model and being making one month ahead predictions for Jan1994, and then expand the sample one month i.e., Jan1960-Jan1994 to get the one month ahead prediction for Feb1994 and repeat this until the sample exhausted Mar2012. this will generate the volatility forecasting for Jan1994-Mar2012.

I saw this post for out of sample recursive one step ahead volatility forecasting via GARCH. and I used it but I am getting only the forecast mean and not the conditional variance/se.

Please can you advise - if this is the right code to follow for my case and how I cant get the conditional variance forecast?

http://forums.eviews.com/viewtopic.php? ... ing#p56704

Code: Select all

'run rolling regression ' set window size !window = 360 ' 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(4) + C(5)*RESID(-1)^2 + C(6)*GARCH(-1) + C(7)*GARCH(-2) garcheqn.ARCH defsprd_var1 c ar(1) ma(1) ' 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

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Mon Mar 22, 2021 6:24 am
by EViews Gareth
Change this line:

Code: Select all

garcheqn.forecast(f=na) yf
to be:

Code: Select all

garcheqn.forecast(f=na) yf yse yvar
Then at the top where you have:

Code: Select all

series fcast
change to:

Code: Select all

series fcast series fgarch
and then change:

Code: Select all

' store forecasts fcast = yf
to be:

Code: Select all

' store forecasts fcast = yf fgarch = yvar

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Mon Mar 22, 2021 3:28 pm
by saraphdnz
Thanks, Gareth for your prompt response and help.

I edited the code as you mentioned and need a bit more help on this.

I can see results for my forecast in the Garch Series but yf, yvar & yse - they all are NA except for the last value. I am not sure why? although I can see all values which I forecasted in the fgarch series.

Code: Select all

'run extended sample ' set window size !window = 408 ' set step size !step = 1 ' get size of workfile !length = 627 ' declare equation for estimation equation garcheqn 'calculate number of rolls !nrolls = @floor((!length-!window)/!step) 'series to store forecast estimates series fcast series fgarch '*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(5) + C(6)*RESID(-1)^2 + C(7)*RESID(-1)^2*(RESID(-1)<0) + C(8)*GARCH(-1) garcheqn.GARCH defsprd_var1 c ar(1) ar(2) ma(1) ' 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 yse yvar ' set sampl to obtain the 4th period observation smpl {%1pere} {%1pere} ' store forecasts fcast = yf fgarch = yvar next

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Mon Mar 22, 2021 3:30 pm
by saraphdnz
Please see the image of my results

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Mon Mar 22, 2021 3:34 pm
by EViews Gareth
yf, yvar & yse are all temporary, discardable series. Ignore them.

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Mon Mar 22, 2021 5:24 pm
by saraphdnz
ok got it - I added these in d(noerr) line and now see the series only in my output file.

I am facing a problem when I try to match the forecasted results obtained from this code and forecasted results obtained from the model (see attached screen).
it seems the code is not rolling ahead of one month to forecast the next value at every step and it remains static 1960M01-1993M12 and forecast the values.
I can see the same results when I use the static forecast based on my sample 1960M01-1993M12 via the model.

Am I doing anything wrong here? selection of window size or length - I am quite confused about what should I edit to make it roll one month ahead and then it forecast and then continuously adding months to do the forecasting?

Please advise.

Regards,
sara

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Tue Mar 23, 2021 2:51 pm
by saraphdnz
Hello Gareth,

Please can you advise further on my post 7? I would really appreciate your help on this.

I checked the code estimation step manually and can see it is adding one month and I also checked the forecasting step that shows the forecast for each month from 1994M01 -2012M03. so I am not sure what I am doing wrong to match my forecast with the model just to verify the forecast results.

I am using the same model and extending dates to estimate it. please see the below screen for your referrence. ga1, ga2, ga3 are the garch forecast from the model.
ga1 (estimation period 1960m01 - 1993m12 - forecast period 1994m01 1994m01)
ga2 (estimation period 1960m01 - 1994m01 - forecast period 1994m02 1994m02)
ga3 (estimation period 1960m01 - 1994m02 - forecast period 1994m03 1994m03)

Regards,
Sara

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Tue Mar 23, 2021 3:02 pm
by EViews Gareth
Nothing immediately jumps out from looking at your code.

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Tue Mar 23, 2021 3:54 pm
by saraphdnz
Attached, my workfile for your reference.

Code: Select all

'run extended sample ' set window size !window = 408 ' 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 series fgarch series fse '*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(5) + C(6)*RESID(-1)^2 + C(7)*RESID(-1)^2*(RESID(-1)<0) + C(8)*GARCH(-1) garcheqn.GARCH defsprd_var1 c ar(1) ar(2) ma(1) ' 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 yse yvar ' set sampl to obtain the 4th period observation smpl {%1pere} {%1pere} ' store forecasts fcast = yf fgarch = yvar fse=yse next smpl @all show fcast.line d(noerr) yf yvar yse

Re: In-Sample one step ahead recursive volatility forecasting via TGARCH

Posted: Wed Mar 24, 2021 2:46 pm
by saraphdnz
Hello there,

I tried to test the forecast results with my model and extend the sample by one month and getting a different forecast value as compared to the one obtained from the code.

I have attached my workfile already with the model and need help.

I would appreciate it if someone can point out the problem/mistake I am doing to get this extended sample forecast?

Regards,
sara