Rolling window forecast of volatility with C-GARCH

For questions regarding programming in the EViews programming language.

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

foivos90
Posts: 6
Joined: Mon Jun 12, 2017 3:11 am

Rolling window forecast of volatility with C-GARCH

Postby foivos90 » Mon Jun 12, 2017 11:08 am

Hi Guys!

I need to do a rolling estimation of a C-GARCH, outputting 1-day ahead forecast for the conditional variance.
I have observations of 4 years and i need a rolling window of the first 2. I found a code in the forum and i adjusted it to my needs. The problem is that the forecast series are on the returns. I need to forecast volatility. The code I used is below. Any help would be useful, thank you for your time!!

Code: Select all

' set window size !window = 521 ' set step size !step = 1 ' get size of workfile !length = @obsrange ' declare equation for estimation equation eq 'calculate number of rolls !nrolls = @floor((!length-!window)/!step) 'matrix to store coefficient estimates matrix(6,!nrolls) coefmat ' where 3 is the number of coefficients '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)+!i-1) %last = @otod(@dtoo(%start)+!i+!window-2) smpl {%first} {%last} ' estimate equation - where the equation is P =c(1) + c(2)*P1(-1) eq.ARCH(cgarch) rt c ' store coefficients colplace(coefmat,eq.@coefs,!j) ' 1-period-ahead forecast %1pers = @otod(@dtoo(%start)+!i+!window-1) %1pere = @otod(@dtoo(%start)+!i+!window) 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*) eq.forecast(f=na) yf ' set sampl to obtain the 1st period observation smpl {%1pere} {%1pere} ' store forecasts fcast = yf next smpl @all 'show coefmat 'show fcast.line d(noerr) yf eq.makegarch garch01

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

Re: Rolling window forecast of volatility with C-GARCH

Postby EViews Gareth » Mon Jun 12, 2017 11:20 am

The equation.forecast proc lets you optionally provide a name for the standard error of the forecast, and the forecast of the variance (if estimated by arch/garch).
http://www.eviews.com/help/helpintro.ht ... 23ww176268

foivos90
Posts: 6
Joined: Mon Jun 12, 2017 3:11 am

Re: Rolling window forecast of volatility with C-GARCH

Postby foivos90 » Tue Jun 13, 2017 3:34 am

Thank you very much Gareth for your quick response, you helped my very much and i changed my code. The problem is that even though i made the series forecasting volatility my results are really poor in performance, plus when i try to estimate it with GARCH(1,1) I have many missing values in the forecast of my volatility.
My changed code for the C-GARCH is below, if anyone can detect any mistakes I would be grateful if he could mention them
Thank you!

Code: Select all

' set window size !window = 521 ' set step size !step = 1 ' get size of workfile !length = @obsrange ' declare equation for estimation equation eq 'calculate number of rolls !nrolls = @floor((!length-!window)/!step) 'matrix to store coefficient estimates matrix(6,!nrolls) coefmat ' where 3 is the number of coefficients 'series to store forecast estimates series fcast series volatfcast '*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)+!i-1) %last = @otod(@dtoo(%start)+!i+!window-2) smpl {%first} {%last} ' estimate equation - where the equation is P =c(1) + c(2)*P1(-1) eq.ARCH(cgarch) rt c eq.makegarch garch01 ' store coefficients colplace(coefmat,eq.@coefs,!j) ' 1-period-ahead forecast %1pers = @otod(@dtoo(%start)+!i+!window-1) %1pere = @otod(@dtoo(%start)+!i+!window) 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*) eq.forecast(f=na) yf garch01_fc ' set sampl to obtain the 1st period observation smpl {%1pere} {%1pere} ' store forecasts fcast = yf volatfcast = garch01_fc next smpl @all 'show coefmat 'show fcast.line d(noerr) yf garch01_fc plot volatfcast garch01


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest