In-Sample one step ahead recursive volatility forecasting via TGARCH

For questions regarding programming in the EViews programming language.

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

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

In-Sample one step ahead recursive volatility forecasting via TGARCH

Postby saraphdnz » Mon Mar 22, 2021 3:21 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Mon Mar 22, 2021 6:24 am

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

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

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

Postby saraphdnz » Mon Mar 22, 2021 3:28 pm

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

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

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

Postby saraphdnz » Mon Mar 22, 2021 3:30 pm

Please see the image of my results
Attachments
Eviews file.JPG
Eviews screens
Eviews file.JPG (188.32 KiB) Viewed 8525 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Mon Mar 22, 2021 3:34 pm

yf, yvar & yse are all temporary, discardable series. Ignore them.

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

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

Postby saraphdnz » Mon Mar 22, 2021 5:24 pm

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
Attachments
eviews screen1.JPG
Screen with forecast
eviews screen1.JPG (221 KiB) Viewed 8517 times

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

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

Postby saraphdnz » Tue Mar 23, 2021 2:51 pm

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
Attachments
Eviews file.JPG
Eviews file.JPG (195.7 KiB) Viewed 8466 times
Last edited by saraphdnz on Tue Mar 23, 2021 3:41 pm, edited 2 times in total.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Tue Mar 23, 2021 3:02 pm

Nothing immediately jumps out from looking at your code.

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

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

Postby saraphdnz » Tue Mar 23, 2021 3:54 pm

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
Attachments
testing recursive defsprd.wf1
(123.23 KiB) Downloaded 303 times

saraphdnz
Posts: 10
Joined: Wed Feb 24, 2021 4:36 pm

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

Postby saraphdnz » Wed Mar 24, 2021 2:46 pm

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests