GARCH rolling regressions
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
GARCH rolling regressions
Hi Gareth
I am trying to run a positive feedback trading model in Eviews 8. Firstly, I run the GARCH M code as follows:
sample s0 @first @first+1
sample s1 @first+2 @last
smpl @all
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
' get starting values
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c y(1)
eq1.makegarch garchm
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
alpha(3) = eq1.c(7)
dof(1) = eq1.c(8)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series res = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append res = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*res(1)^2 + alpha(3)*sig2(1)
ll1.append z = res/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e5)
show ll1.output
I then estimate the TGARCH model using the following code:
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
coef(1) thresh = 0
' get starting values
eq1.arch(1,1,thrsh=1,archm=VAR,ged,backcast=1) y c y(1)
eq1.makegarch garchm
eq1.arch(1,1,thrsh=1,archm=VAR,ged,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
thresh(1) = eq1.c(7)
alpha(3) = eq1.c(8)
dof(1) = eq1.c(9)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series res = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append res = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*res(1)^2 + alpha(3)*sig2(1) + thresh(1)*res(1)^2*(res(1)<0)
ll1.append z = res/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e5)
show ll1.output
My problem is I want to estimate rolling regressions using daily data. I simultaneously estimate the mean and conditional variance for each individual share, every month end during the period 20042010. These estimations are done each month using the daily returns for the past six months, on a rolling basis. For example, for the month of July 2004, I will use the daily returns for January 2004  June 2004. I have tried to fiddle with the basic rolling regressions code that was provided on this site but I am failing to code it correctly. May you please help me on how I can go about it in programming the correct code. I have also attached the daily returns work file that I am using.
Thank you
I am trying to run a positive feedback trading model in Eviews 8. Firstly, I run the GARCH M code as follows:
sample s0 @first @first+1
sample s1 @first+2 @last
smpl @all
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
' get starting values
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c y(1)
eq1.makegarch garchm
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
alpha(3) = eq1.c(7)
dof(1) = eq1.c(8)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series res = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append res = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*res(1)^2 + alpha(3)*sig2(1)
ll1.append z = res/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e5)
show ll1.output
I then estimate the TGARCH model using the following code:
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
coef(1) thresh = 0
' get starting values
eq1.arch(1,1,thrsh=1,archm=VAR,ged,backcast=1) y c y(1)
eq1.makegarch garchm
eq1.arch(1,1,thrsh=1,archm=VAR,ged,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
thresh(1) = eq1.c(7)
alpha(3) = eq1.c(8)
dof(1) = eq1.c(9)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series res = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append res = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*res(1)^2 + alpha(3)*sig2(1) + thresh(1)*res(1)^2*(res(1)<0)
ll1.append z = res/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e5)
show ll1.output
My problem is I want to estimate rolling regressions using daily data. I simultaneously estimate the mean and conditional variance for each individual share, every month end during the period 20042010. These estimations are done each month using the daily returns for the past six months, on a rolling basis. For example, for the month of July 2004, I will use the daily returns for January 2004  June 2004. I have tried to fiddle with the basic rolling regressions code that was provided on this site but I am failing to code it correctly. May you please help me on how I can go about it in programming the correct code. I have also attached the daily returns work file that I am using.
Thank you
 Attachments

 daily returns.wf1
 Daily returns for Company A
 (69.86 KiB) Downloaded 169 times

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12199
 Joined: Tue Sep 16, 2008 5:38 pm
Re: GARCH rolling regressions
Hi Gareth
Thank you for the response. I used the logl object as per the model's specification and so as to maximise the likelihood function. Is this problematic given my current codes?
For the rolling regressions, I had to add the this third program code and I have been trying to use the basic rolling regression code that you provided on the forum:
'create some data
create u 800
series y=nrnd
series x1=nrnd
series x2=nrnd
series z=nrnd
'
'run rolling regression
' set window size
!window = 180
' set step size
!step = 1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @round((!length!window)/!step)
'matrix to store coefficient estimates
matrix(3,!nrolls) coefmat ' where 3 is the number of coefficients
'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 to estimation period
smpl @first+!i1 @first+!i+!window2
' estimate equation  where the equation is y=c(1) + c(2)*x1 + c(3)*x2
eq1.ls y c x1 x2
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
My problem was in trying to modify this code so that it suits my data and method.
Thank you
Thank you for the response. I used the logl object as per the model's specification and so as to maximise the likelihood function. Is this problematic given my current codes?
For the rolling regressions, I had to add the this third program code and I have been trying to use the basic rolling regression code that you provided on the forum:
'create some data
create u 800
series y=nrnd
series x1=nrnd
series x2=nrnd
series z=nrnd
'
'run rolling regression
' set window size
!window = 180
' set step size
!step = 1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @round((!length!window)/!step)
'matrix to store coefficient estimates
matrix(3,!nrolls) coefmat ' where 3 is the number of coefficients
'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 to estimation period
smpl @first+!i1 @first+!i+!window2
' estimate equation  where the equation is y=c(1) + c(2)*x1 + c(3)*x2
eq1.ls y c x1 x2
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
My problem was in trying to modify this code so that it suits my data and method.
Thank you
Re: GARCH rolling regressions
What Gareth means is that, you do not have to use a LogL object if you are trying to estimate a regular GARCH or GARCHinmean model as they are already builtin.
I wrote the code you use for another user so as to allow him/her to estimate the effect of the interaction between conditional volatility and the lagged dependent variable (i.e. garchm*y(1)) in the mean equation. If you only need garchm in the mean equation, then the following part of the code will be enough:
There is really nothing special about the Rolling part of the model and you already have a good example.
I wrote the code you use for another user so as to allow him/her to estimate the effect of the interaction between conditional volatility and the lagged dependent variable (i.e. garchm*y(1)) in the mean equation. If you only need garchm in the mean equation, then the following part of the code will be enough:
Code: Select all
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c y(1)
There is really nothing special about the Rolling part of the model and you already have a good example.
Re: GARCH rolling regressions
Hi,
I'm trying to estimate a rolling regression garch with a moving window of 500 observations, and a 1 period ahead forecast of returns and conditional variance.
however may variance series only have the last 500 forecasts, it should have 3615.
'declare series
series r
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(4,!nrolls) coef1
'series to store forecast estimates
series rf
series volf
'catching start and end points
%start = "@first@"
%end = "@last"
'variable keeping track of how many solls we have done
!j=0
'move sample !step pbs 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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
'estimate equation
eq1.arch(1, 1, h) r ar(1)
'store coefficients
colplace(coef1,eq1.@coefs,!j)
'1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1)
%1pere = @otod(@dtoo(%start)+!i+!window)
if @dtoo(%end) < @dtoo(%1pere) then 'whether fcast end point > wfile end point
exitloop
endif
'set smpl for forecasting period
smpl {%1pers} {%1pere}
'forecast with command forecast
eq1.forecast(f=na) pf
'conditional volatilities
eq1.makegarch volf
'set sample to obtain 1period observation
smpl {%pere} {%pere}
'store forecasts
rf = pf
next
smpl @all
show coefgar11
show rf.line
show volf.line
d(noerr) pf
d(noerr) vf
I very appreciate some hint
I'm trying to estimate a rolling regression garch with a moving window of 500 observations, and a 1 period ahead forecast of returns and conditional variance.
however may variance series only have the last 500 forecasts, it should have 3615.
'declare series
series r
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(4,!nrolls) coef1
'series to store forecast estimates
series rf
series volf
'catching start and end points
%start = "@first@"
%end = "@last"
'variable keeping track of how many solls we have done
!j=0
'move sample !step pbs 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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
'estimate equation
eq1.arch(1, 1, h) r ar(1)
'store coefficients
colplace(coef1,eq1.@coefs,!j)
'1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1)
%1pere = @otod(@dtoo(%start)+!i+!window)
if @dtoo(%end) < @dtoo(%1pere) then 'whether fcast end point > wfile end point
exitloop
endif
'set smpl for forecasting period
smpl {%1pers} {%1pere}
'forecast with command forecast
eq1.forecast(f=na) pf
'conditional volatilities
eq1.makegarch volf
'set sample to obtain 1period observation
smpl {%pere} {%pere}
'store forecasts
rf = pf
next
smpl @all
show coefgar11
show rf.line
show volf.line
d(noerr) pf
d(noerr) vf
I very appreciate some hint
Re: GARCH rolling regressions
arga wrote:I very appreciate some hint
Then you should also post your workfile along with your code. Unless there is an obvious logical mistake or a syntax error in the code, then it is extremely difficult to pinpoint to source of the problem. The data and the structure of workfile are very very important components of a program code.
Since another user is also interested in Rolling garch model in this thread, I "tried" to clean and correct the code you posted in order to point both of you in the right direction. I am really not sure if it does what you want, but should at least give you the idea:
Code: Select all
mode quiet
'declare series to store the output
series rf
series volf
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(4,!nrolls) coef1
'catching start and end points
%start = r.@first
%end = r.@last
'variable keeping track of how many rolls we have done
!j=0
'move sample !step pbs 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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
'estimate equation
eq1.arch(1, 1, h) r ar(1)
'store coefficients
colplace(coef1,eq1.@coefs,!j)
'1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1)
'set smpl for forecasting period
smpl {%1pers} {%1pers}
'forecast with command forecast
eq1.forecast(f=na) pf stdevf garchf
'store forecasts
rf(@dtoo(%1pers)) = pf(@dtoo(%1pers))
volf(@dtoo(%1pers)) = garchf(@dtoo(%1pers))
statusline !i of !nrolls
next
smpl @all
show coef1
show rf.line
show volf.line
d(noerr) pf
d(noerr) stdevf
Re: GARCH rolling regressions
Hi trubador
Thank you for the response and I also estimate the effect of the interaction between conditional volatility and the lagged dependent variable that is why I used your code . Its just that I am not well versed with programming so I wanted to check if the certain program codes I am trying to use do make sense. So as I said earlier on, with the model that I am trying to run, which is called the positive feedback trading model, I first estimate the GARCHinmean model, then estimate the TGARCH model. Lastly since this is done on a rolling basis, I use the rolling regressions code. With that basic rolling regression code, what are the main elements that I have to change for the codes to match my data and method?
Thank you.
Thank you for the response and I also estimate the effect of the interaction between conditional volatility and the lagged dependent variable that is why I used your code . Its just that I am not well versed with programming so I wanted to check if the certain program codes I am trying to use do make sense. So as I said earlier on, with the model that I am trying to run, which is called the positive feedback trading model, I first estimate the GARCHinmean model, then estimate the TGARCH model. Lastly since this is done on a rolling basis, I use the rolling regressions code. With that basic rolling regression code, what are the main elements that I have to change for the codes to match my data and method?
Thank you.
Re: GARCH rolling regressions
The rolling code above works for the simplest case, where you can estimate the model with a single line of code. In your case, the estimation is a procedure by itself. So you should find a way to embed your full estimation into the following part of the rolling code:
Since there are several different ways to do a rolling regression, it may be difficult to find a generic code. But, should not be that difficult to modify it...
Code: Select all
...
'estimate equation
eq1.arch(1, 1, h) r ar(1)
...
Since there are several different ways to do a rolling regression, it may be difficult to find a generic code. But, should not be that difficult to modify it...
Re: GARCH rolling regressions
Thank you, let me try to do that.
Re: GARCH rolling regressions
Hi
I have tried to embed my full estimation procedure into a single code as you stipulated. My mean equation is: r_t=α+θσ_t^2+(ϕ_0+ϕ_1 σ_t^2 ) r_(t1)+ε_t and my variance equation is : σ_t^2=ω+βε_(t1)^2+λσ_(t1)^2+δS_(t1) ε_(t1)^2.To estimate my model, for each individual share, every monthend during the sample period, the conditional mean and conditional variance equations are simultaneously estimated using daily returns for the past six months. These equations are estimated for all the shares in the sample. The same estimations are conducted in the next month using daily returns for the immediately preceding six months and this procedure is done monthly on a rolling basis. Thus, given that the sample period commenced in January 2004, the first equation is estimated at the end of June 2004 using January to June data and then estimates for July are obtained using February to July data thus maintaining the sixmonth window but rolling the data forward. Six months of daily data translated into approximately 125 observations that are used for each regression. I also need to store the threshold coefficients for each month and the respective student t statistics. I have tried to run the code and I am getting results but an error pops up that: c is not a member or procedure of eq1 in dof(1) =eq1.c(9). I have also uploaded the work file and the code is as follows:
I have tried to embed my full estimation procedure into a single code as you stipulated. My mean equation is: r_t=α+θσ_t^2+(ϕ_0+ϕ_1 σ_t^2 ) r_(t1)+ε_t and my variance equation is : σ_t^2=ω+βε_(t1)^2+λσ_(t1)^2+δS_(t1) ε_(t1)^2.To estimate my model, for each individual share, every monthend during the sample period, the conditional mean and conditional variance equations are simultaneously estimated using daily returns for the past six months. These equations are estimated for all the shares in the sample. The same estimations are conducted in the next month using daily returns for the immediately preceding six months and this procedure is done monthly on a rolling basis. Thus, given that the sample period commenced in January 2004, the first equation is estimated at the end of June 2004 using January to June data and then estimates for July are obtained using February to July data thus maintaining the sixmonth window but rolling the data forward. Six months of daily data translated into approximately 125 observations that are used for each regression. I also need to store the threshold coefficients for each month and the respective student t statistics. I have tried to run the code and I am getting results but an error pops up that: c is not a member or procedure of eq1 in dof(1) =eq1.c(9). I have also uploaded the work file and the code is as follows:
Code: Select all
'create some data
create d5 2004 2013
series y=nrnd
series resid=nrnd
'
'run rolling regression
' set window size
!window = 125
' set step size
!step = 1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @round((!length!window)/!step)
'matrix to store coefficient estimates
matrix(9,!nrolls) coefmat ' where 9 is the number of coefficients
'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 to estimation period
smpl @first+!i1 @first+!i+!window2
' estimate equation
sample s0 @first @first+1
sample s1 @first+2 @last
smpl @all
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
' get starting values
equation eq1.arch(1,1,ged,archm=stdev,backcast=1) y c y(1)
eq1.makegarch garchm
equation eq1.arch(1,1,ged,archm=stdev,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
alpha(3) = eq1.c(7)
dof(1) = eq1.c(8)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series resid = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append resid = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*resid(1)^2 + alpha(3)*sig2(1)
ll1.append z = resid/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(1) thresh = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
' get starting values
eq1.arch(1,1,thrsh=1,archm=stdev,ged,backcast=1) y c y(1)
eq1.makegarch garchm
eq1.arch(1,1,thrsh=1,archm=stdev,ged,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
thresh(1) = eq1.c(7)
alpha(3) = eq1.c(8)
dof(1) = eq1.c(9)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series resid = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append resid = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*resid(1)^2 + alpha(3)*sig2(1) + thresh(1)*resid(1)^2*(resid(1)<0)
ll1.append z = resid/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e5)
show ll1.output
'store coefficients
colplace(coef1,eq1.@coefs,!j)
next
show coef1
 Attachments

 daily returns.wf1
 (69.86 KiB) Downloaded 135 times
Re: GARCH rolling regressions
Student15 wrote:I have tried to run the code and I am getting results but an error pops up that: c is not a member or procedure of eq1 in dof(1) =eq1.c(9).
1) That is because eq1 has only 7 coefficients. The problem is due to wrong syntax in "...,archm=stdev,..." It should read: "...archm=sd..."
2) Your storage matrix should be coefmat, not coef1.
3) You cannot use sample objects inside a loop like that.
Re: GARCH rolling regressions
Hi Trubador
Thank you for the quick response, let me try to effect those changes.
Thank you for the quick response, let me try to effect those changes.
Re: GARCH rolling regressions
Hi Trubador
Thank you for those corrections, I have effected them and that problem was solved. However, there is another error: Matrix size mismatch in "colplace(coefmat,Eq1.@coefs,1) and the coefficients are not being stored. I have tried to follow some links on the forum such as viewtopic.php?f=5&t=5272, but I am failing to deal with this error. May you please help me in correcting this error. Thank you. The current code is:
Thank you for those corrections, I have effected them and that problem was solved. However, there is another error: Matrix size mismatch in "colplace(coefmat,Eq1.@coefs,1) and the coefficients are not being stored. I have tried to follow some links on the forum such as viewtopic.php?f=5&t=5272, but I am failing to deal with this error. May you please help me in correcting this error. Thank you. The current code is:
Code: Select all
'run rolling regression
' set window size
!window = 126
' set step size
!step = 21
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @ceiling((!length!window)/!step)
'matrix to store coefficient estimates
matrix(8,!nrolls) coefmat ' where 8 is the number of coefficients
matrix(8,!nrolls) tmat
'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 to estimation period
smpl @first+!i1 @first+!i1+!window
' estimate equation
sample s0 @first @first+1
sample s1 @first+2 @last
smpl @all
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
' get starting values
equation eq1.arch(1,1,ged,archm=sd,backcast=1) y c y(1)
eq1.makegarch garchm
equation eq1.arch(1,1,ged,archm=sd,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
alpha(3) = eq1.c(7)
dof(1) = eq1.c(8)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series resid = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append resid = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*resid(1)^2 + alpha(3)*sig2(1)
ll1.append z = resid/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(1) thresh = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0
' get starting values
eq1.arch(1,1,thrsh=1,archm=sd,ged,backcast=1) y c y(1)
eq1.makegarch garchm
eq1.arch(1,1,thrsh=1,archm=sd,ged,backcast=1) y c garchm*y(1) y(1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
thresh(1) = eq1.c(7)
alpha(3) = eq1.c(8)
dof(1) = eq1.c(9)
mu(1) = eq1.@se^2
' set presample values of expressions in logl
series sig2 = mu(1)
series resid = resid
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append resid = y  beta(2)  beta(1)*sig2  beta(3)*sig2*y(1) beta(4)*y(1)
ll1.append sig2 = alpha(1)+ alpha(2)*resid(1)^2 + alpha(3)*sig2(1) + thresh(1)*resid(1)^2*(resid(1)<0)
ll1.append z = resid/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1)))  log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e5)
show ll1.output
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
colplace(tmat,eq1.@coefs,!j)
next
show coefmat
Re: GARCH rolling regressions
Hi,
I´m trying to do a rolling regression with fix window of 500 observations, and obtain the one step ahead vol. forecasts of an APARCH model whoever I get an error.
Can you help me with this problem?
mode quiet
'declare series to store the output
series rf
series volf
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(5,!nrolls) coef1
'catching start and end points
%start = r.@first
%end = r.@last
'variable keeping track of how many rolls we have done
!j=0
'move sample !step pbs 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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
'estimate equation
eq1.arch(1, 1, parch, asy=1 ) r
'store coefficients
colplace(coef1,eq1.@coefs,!j)
'1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1)
'set smpl for forecasting period
smpl {%1pers} {%1pers}
'forecast with command forecast
eq1.forecast(f=na) pf stdevf garchf
'store forecasts
rf(@dtoo(%1pers)) = pf(@dtoo(%1pers))
volf(@dtoo(%1pers)) = garchf(@dtoo(%1pers))
statusline !i of !nrolls
next
smpl @all
show coef1
show rf.line
show volf.line
d(noerr) pf
d(noerr) stdevf
I´m trying to do a rolling regression with fix window of 500 observations, and obtain the one step ahead vol. forecasts of an APARCH model whoever I get an error.
Can you help me with this problem?
mode quiet
'declare series to store the output
series rf
series volf
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(5,!nrolls) coef1
'catching start and end points
%start = r.@first
%end = r.@last
'variable keeping track of how many rolls we have done
!j=0
'move sample !step pbs 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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
'estimate equation
eq1.arch(1, 1, parch, asy=1 ) r
'store coefficients
colplace(coef1,eq1.@coefs,!j)
'1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1)
'set smpl for forecasting period
smpl {%1pers} {%1pers}
'forecast with command forecast
eq1.forecast(f=na) pf stdevf garchf
'store forecasts
rf(@dtoo(%1pers)) = pf(@dtoo(%1pers))
volf(@dtoo(%1pers)) = garchf(@dtoo(%1pers))
statusline !i of !nrolls
next
smpl @all
show coef1
show rf.line
show volf.line
d(noerr) pf
d(noerr) stdevf
 Attachments

 error.dot
 (95 KiB) Downloaded 129 times

 r serie.WF1
 (109.14 KiB) Downloaded 118 times
Re: GARCH rolling regressions
Hey there,
I want to run a rolling regression for a GARCH(1,1), mean equation being an ARMAProcess. I use monthly data on US CPI from 1973.01  2015.12. I'm using EViews 9.5 Student Version. I executed following codes in chronological order:
'declare series to store the output
series rf
series volf
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
Everytime I want to execute the code for "calculate number of rolls" the error message "!STEP is not defined" pops up. When I execute "!step = 1", EViews tells me !STEP successfully computed, but the error message "!STEP is not defined" keeps popping up when I want to calculate the number of rolls. What am I doing wrong? Thanks for the help!
I want to run a rolling regression for a GARCH(1,1), mean equation being an ARMAProcess. I use monthly data on US CPI from 1973.01  2015.12. I'm using EViews 9.5 Student Version. I executed following codes in chronological order:
'declare series to store the output
series rf
series volf
'set window size
!window = 500
'set step size
!step = 1
'get size of workfile
!length = @obsrange
'declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
Everytime I want to execute the code for "calculate number of rolls" the error message "!STEP is not defined" pops up. When I execute "!step = 1", EViews tells me !STEP successfully computed, but the error message "!STEP is not defined" keeps popping up when I want to calculate the number of rolls. What am I doing wrong? Thanks for the help!
Who is online
Users browsing this forum: Bing [Bot] and 6 guests