GARCH-M Code
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
GARCH-M Code
Hi Gareth,
I came up with a program to estimate a GARCH-M with an additional interaction term (Y(-1)*GARCH). My conditional mean equation is r_t= α+ μ(σ_t^2 )+(γ_0+γ_1 σ_t^2) r_(t-1)+ ε_t and my variance equation is σ_t^2= α_0+ α_1 ε_(t-1)^2+ βσ_(t-1)^2+ δS_(t-1) ε_(t-1)^2. I managed to get some results but l am not too sure if the code is entirely correct (I have pasted it below and also attached my workfile). I also want to estimate the model assuming that the standard error terms follow a generalized error distribution (GED) instead of a normal distribution. How do l edit my code to account for this?
Kind regards
Arnold
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) mu = 0
' get starting values
equation eq1.arch(1,1, archm=VAR,backcast=1) y c y(-1)
eq1.makegarch garchm
equation eq1.arch(1,1, 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)
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(@dnorm(z)) - log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e-5)
show ll1.output
I came up with a program to estimate a GARCH-M with an additional interaction term (Y(-1)*GARCH). My conditional mean equation is r_t= α+ μ(σ_t^2 )+(γ_0+γ_1 σ_t^2) r_(t-1)+ ε_t and my variance equation is σ_t^2= α_0+ α_1 ε_(t-1)^2+ βσ_(t-1)^2+ δS_(t-1) ε_(t-1)^2. I managed to get some results but l am not too sure if the code is entirely correct (I have pasted it below and also attached my workfile). I also want to estimate the model assuming that the standard error terms follow a generalized error distribution (GED) instead of a normal distribution. How do l edit my code to account for this?
Kind regards
Arnold
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) mu = 0
' get starting values
equation eq1.arch(1,1, archm=VAR,backcast=1) y c y(-1)
eq1.makegarch garchm
equation eq1.arch(1,1, 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)
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(@dnorm(z)) - log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e-5)
show ll1.output
- Attachments
-
- main workfile.wf1
- (113 KiB) Downloaded 213 times
Re: GARCH-M Code
Replace the likelihood function:
with the following:
Do not forget to define a coefficient vector of "dof" and assign a starting value prior to the estimation.
If you would like to get an initial estimate of the starting value of dof(1), you should also adjust the relevant parts of the code:
Code: Select all
ll1.append logl = log(@dnorm(z)) - log(sig2)/2Code: Select all
ll1.append logl = log(@dged(z,dof(1))) - log(sig2)/2If you would like to get an initial estimate of the starting value of dof(1), you should also adjust the relevant parts of the code:
Code: Select all
...
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c y(-1)
...
equation eq1.arch(1,1,ged,archm=VAR,backcast=1) y c garchm*y(-1) y(-1)
...
dof(1) = eq1.c(8)
...-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
Re: GARCH-M Code
Hi Trubador
Thank you very much for your assistance. However, I am still a little confused with regards to assigning a starting value for "dof". I made the changes you highlighted and tried running the code but it gave me an error message "DOF is not defined or is an illegal command in 'DOF(1) = EQ1.C(8)". How can l sort this out? I have pasted the edited code and attached the main workfile.
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) 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=1e-5)
show ll1.output
Thank you very much for your assistance. However, I am still a little confused with regards to assigning a starting value for "dof". I made the changes you highlighted and tried running the code but it gave me an error message "DOF is not defined or is an illegal command in 'DOF(1) = EQ1.C(8)". How can l sort this out? I have pasted the edited code and attached the main workfile.
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) 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=1e-5)
show ll1.output
- Attachments
-
- main workfile (GED).WF1
- (53.06 KiB) Downloaded 230 times
Re: GARCH-M Code
You should declare it as a coefficient vector before calling it:
Code: Select all
...
coef(1) dof = 0
...-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
Re: GARCH-M Code
Got it! Thank you very much for your assistance.
-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
Re: GARCH-M Code
Hi Trubador
I now want to extend my conditional variance equation to account for a leverage effect using a TGARCH (1,1) specification but l am not sure of how l can modify my code. Do l use the modification below and do l have to add an additional coefficient for it as well?
.....
equation eq01.arch(1,1,thrsh=1) y c …
.....
I now want to extend my conditional variance equation to account for a leverage effect using a TGARCH (1,1) specification but l am not sure of how l can modify my code. Do l use the modification below and do l have to add an additional coefficient for it as well?
.....
equation eq01.arch(1,1,thrsh=1) y c …
.....
Re: GARCH-M Code
Since you drop the "ged" in the meantime, total number of coefficients does not change. However, the order of coefficients does. For instance, alpha(3) is no longer the 7th coefficient. You should carefully check them.
Also, you have to adjust the log likelihood and add a threshold term to the variance equation. Suppose, you have defined a coefficient vector, "thresh", for that purpose. You should add the following term:
Also, you have to adjust the log likelihood and add a threshold term to the variance equation. Suppose, you have defined a coefficient vector, "thresh", for that purpose. You should add the following term:
Code: Select all
...+ thresh(1)*res(-1)^2*(res(-1)<0)-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
Re: GARCH-M Code
Thank you for the response. I want to include the "ged" in the code. I tried editing it and running it and it gave me an error "C is not a member or procedure of EQ1 in DOF(1)= EQ1.C(8)". Did l make the correct modifications? I have pasted them below
....
' 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 = 1
' get starting values
equation eq1.arch(1,1,thresh=1,ged,backcast=1) y c y(-1)
eq1.makegarch garchm
equation eq1.arch(1,1, thresh=1,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)
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) + 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
.....
....
' 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 = 1
' get starting values
equation eq1.arch(1,1,thresh=1,ged,backcast=1) y c y(-1)
eq1.makegarch garchm
equation eq1.arch(1,1, thresh=1,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)
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) + 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
.....
Re: GARCH-M Code
Each specification requires different number of parameters to be estimated. So when you change the model structure, you should define the coefficients accordingly. And there are several syntax errors in your code:
Again, be careful with the order of estimated coefficients. You can check the correct order from eq1:
replace "thresh=1" with "thrsh=1". Also, do not drop in-mean spec:equation eq1.arch(1,1, thresh=1,ged,backcast=1) y c garchm*y(-1) y(-1)
Code: Select all
...
eq1.arch(1,1,thrsh=1,archm=VAR,ged,backcast=1) y c y(-1)
...
eq1.arch(1,1,thrsh=1,archm=VAR,ged,backcast=1) y c garchm*y(-1) y(-1)
...Code: Select all
...
thresh(1) = eq1.c(7)
alpha(3) = eq1.c(8)
dof(1) = eq1.c(9)
...-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
Re: GARCH-M Code
Okay, thank you very much!!!
-
arnold.musadzi
- Posts: 7
- Joined: Sun Dec 07, 2014 12:22 pm
Re: GARCH-M Code
Hi Trubador
I want to include a dummy variable in my model that captures sentiment (also assuming that the errors terms follow the GED). My re-formulated mean equation is as follows:
r_t= α_H D_t+ α_L (1-D_t )+ u_H D_t σ_t^2+u_L (1-D_t ) σ_t^2+(γ_0+γ_1 σ_t^2 ) r_(t-1)+ε_t
where D_t = 1 in a high sentiment period (in which case the value of the sentiment index on a particular day was higher than the median value), and D_t = 0 in a low sentiment period (below the median value). α_H and α_L represent average returns in a high sentiment and low sentiment periods respectively and u_H and u_L are the parameters of the conditional variance (σ_t^2) in both high and low sentiment periods respectively. My variance equation is the same. How do l modify my code to account for this dummy variable? I have attached my workfile for your perusal (the dummy variable is the one one named series01). Your assistance will be greatly appreciated.
I want to include a dummy variable in my model that captures sentiment (also assuming that the errors terms follow the GED). My re-formulated mean equation is as follows:
r_t= α_H D_t+ α_L (1-D_t )+ u_H D_t σ_t^2+u_L (1-D_t ) σ_t^2+(γ_0+γ_1 σ_t^2 ) r_(t-1)+ε_t
where D_t = 1 in a high sentiment period (in which case the value of the sentiment index on a particular day was higher than the median value), and D_t = 0 in a low sentiment period (below the median value). α_H and α_L represent average returns in a high sentiment and low sentiment periods respectively and u_H and u_L are the parameters of the conditional variance (σ_t^2) in both high and low sentiment periods respectively. My variance equation is the same. How do l modify my code to account for this dummy variable? I have attached my workfile for your perusal (the dummy variable is the one one named series01). Your assistance will be greatly appreciated.
- Attachments
-
- main workfile (sent).wf1
- (75.15 KiB) Downloaded 195 times
Re: GARCH-M Code
You'd better learn how to modify EViews codes. Otherwise, each time reformulate the equation you'll need assistance. A typical research would require a lot of testing and hence reformulations. Below are the parts that need to be modified so as to do what you want:
Code: Select all
...
coef(6) beta = 0
...
eq1.arch(1,1,thrsh=1,ged,backcast=1) y = c(1) + c(2)*garchm + c(3)*series01 + c(4)*series01*garchm + (c(5)+c(6)*garchm)*y(-1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
beta(5) = eq1.c(5)
beta(6) = eq1.c(6)
alpha(1) = eq1.c(7)
alpha(2) = eq1.c(8)
thresh(1) = eq1.c(9)
alpha(3) = eq1.c(10)
dof(1) = eq1.c(11)
mu(1) = eq1.@se^2
...
ll1.append res = y -(beta(2) + beta(1)*sig2 + beta(3)*series01 + beta(4)*series01*sig2 + (beta(5)+beta(6)*sig2)*y(-1))
...Who is online
Users browsing this forum: No registered users and 2 guests
