Hello,
i wrote my own logLikelihood-function for a GARCH-model.
I set up my own logLikelihood-function with help from the EViews sample programms. The errors are gaussian distributed.
How do I add the GJR-Coefficient (T-GARCH) in my Variance Equation?
ll1.append sig2 = omega(1)+alpha(1)*res(-1)^2 +beta(1)*sig2(-1)
I hope someone can help me.
Is there a command for Bollerslev-Wooldbridge robust errors in the logLikelihood-function?
Thanks!!!
Command for GJR and Bollerslev-Woolridge error in GARCH-Code
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Re: Command for GJR and Bollerslev-Woolridge error in GARCH-
Hi morbo-23,
I wrote something that might help you. I am not sure, if it is really correct. But I'd appreciate it if you could take a look at it.
I have arbitrarily taken a AR(2) for the conditional mean.
Regarding your Bollerslev_Wooldridge error question: You said that you assumed a Gaussian error distribution if I understood you correctly. Then you do not need the quasi maximum likelihood approach. The parameter estimats do not change anyways. Only the variance-covariance matrix changes.
Do you know how to tell Eviews (in the code above) when maximizing the loglikelihood function to use the BHHH algorithm rather than Marquardt????
Sincerely yours,
Z
I wrote something that might help you. I am not sure, if it is really correct. But I'd appreciate it if you could take a look at it.
I have arbitrarily taken a AR(2) for the conditional mean.
Code: Select all
'##################################################
'AR(2) - GJR-GARCH(1,1)
'##################################################
'turn to page of question in workfile
pageselect test
'set counter which stops the time how long eviews needs to do the computation
tic
'take first log naturalis difference of (in my case) real GDP series to get growth rate expressions
series y = dlog(rgdp)
' declare coef vectors to use in conditional mean and GARCH equation
coef(1) mu = .1
coef(2) phi = .1
coef(1) omega
coef(1) alpha = .1
coef(1) beta = .8
coef(1) gamma = .2
' get starting values for the parameters in GARCH equation which will be estimated by ML from ARMA(p,q) OLS estimation
equation temp.ls y c ar(1) ar(2)
mu(1) = temp.c(1)
phi(1) = temp.c(2)
phi(2) = temp.c(3)
' Define name of the logl object
logl bedvar
' add a object named loglike to the logl object
bedvar.append @logl loglike
'generate residuals of the ARMA(p,q) condittional mean
bedvar.append res = y - mu(1) + @nan( - phi(1)*y(-1) - phi(2)*y(-2), 0)
'generate dummy for the GARCH equation
bedvar.append dummy = @nan(@recode(res(-1)<0, 1, 0),0)
'define condtitional variance
bedvar.append sig2 = @nan(omega(1) + alpha(1) * ( res(-1) )^2 + gamma(1)*( res(-1) )^2*dummy+ beta(1) * sig2(-1),1)
' Log-Likelihood function assuming Gaussian white noise errors. I was not exact regarding the first term which should say log(Pi) because for maximization the first derivative of loglike is taken and therefore the first (constant) terms drops out anyways
bedvar.append loglike = @nan( - 0.5 * log( 2* 3.14 ) - 0.5 * log(sig2) - 0.5*( res )^2 , 1 )
'do the algorithm default setting is the MARquardt algorithm
bedvar.ml(showopts)
'skirmish
' Save information criteria
scalar aic = bedvar.@aic
scalar bic = bedvar.@schwarz
scalar hqc = bedvar.@hq
' save the computation time in a scalar named elapsed
scalar elapsed = @toc
Regarding your Bollerslev_Wooldridge error question: You said that you assumed a Gaussian error distribution if I understood you correctly. Then you do not need the quasi maximum likelihood approach. The parameter estimats do not change anyways. Only the variance-covariance matrix changes.
Do you know how to tell Eviews (in the code above) when maximizing the loglikelihood function to use the BHHH algorithm rather than Marquardt????
Sincerely yours,
Z
Re: Command for GJR and Bollerslev-Woolridge error in GARCH-
bedvar.ml(b,showopts)Do you know how to tell Eviews (in the code above) when maximizing the loglikelihood function to use the BHHH algorithm rather than Marquardt????
Re: Command for GJR and Bollerslev-Woolridge error in GARCH-
Hi Zappa,
i solved the GJR-part in a similiar way.
I use a gaussian distribution for my errors. I used the one from the sample files. There is also a code for an ar(1)-garch model with t-distribution. Maybe the code can provide some help for writing an ar-garch-model.
Regarding the Bollerslev Robust Standard Errors: The Coeficients doesnt change, only the Covariance. But how do I calculate the robust Covariance? If you use the drop-down menu for ARCH-models you can simply choose bollerslev-robust-errors. In the programming manual you can find that h is the command for those robust errors. But it didnt work in my code.
I hope someone can help me with the calculation of the robust covariance (bollerslev-woolridge robust errors).
See my Code below:
f <- is a dummy-variabel that takes the value of 1 after a certain date
r_csi <- returns of the csi300 index
r_hs <- returns of Hang seng- Index
r_sp <- returns of S&P500
rl <- first lag of returns
I hope someone can help me with the calculation of the robust covariance (bollerslev-woolridge robust errors).
Thanks
i solved the GJR-part in a similiar way.
I use a gaussian distribution for my errors. I used the one from the sample files. There is also a code for an ar(1)-garch model with t-distribution. Maybe the code can provide some help for writing an ar-garch-model.
Regarding the Bollerslev Robust Standard Errors: The Coeficients doesnt change, only the Covariance. But how do I calculate the robust Covariance? If you use the drop-down menu for ARCH-models you can simply choose bollerslev-robust-errors. In the programming manual you can find that h is the command for those robust errors. But it didnt work in my code.
I hope someone can help me with the calculation of the robust covariance (bollerslev-woolridge robust errors).
See my Code below:
f <- is a dummy-variabel that takes the value of 1 after a certain date
r_csi <- returns of the csi300 index
r_hs <- returns of Hang seng- Index
r_sp <- returns of S&P500
rl <- first lag of returns
Code: Select all
' set sample
sample s1 2 2
sample s2 3 1590
smpl s2
' get starting values from Gaussian ARCH
equation eq1
eq1.ls r_csi c Di Mi Do Fr r_sp(-1) r_hs r_csi(-1) r_csi(-3) f*r_csi(-1) f*r_csi(-3)
' declare and initialize parameters
coef(1) mu = eq1.c(1)
coef(1) d1 = eq1.c(2)
coef(1) d2 = eq1.c(3)
coef(1) d3 = eq1.c(4)
coef(1) d4 = eq1.c(5)
coef(1) gs = eq1.c(6)
coef(1) ls = eq1.c(7)
coef(1) rl = eq1.c(8)
coef(1) rl3 = eq1.c(9)
coef(1) f_rl = eq1.c(10)
coef(1) f_rl3 = eq1.c(11)
coef(1) omega = 0.00004
coef(1) alpha = 0.15
coef(1) beta = 0.6
coef(1) gamma = 0.05
coef(1) dum = 0
' set presample values of expressions in logl
smpl s1
series sig2 = omega(1)
series res = 0
' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append res = r_csi-mu(1)-d1(1)*Di-d2(1)*Mi-d3(1)*Do-d4(1)*Fr-gs(1)*r_sp(-1)-ls(1)*r_hs-rl(1)*r_csi(-1)-rl3(1)*r_csi(-3)-f_rl(1)*f*r_csi(-1)-f_rl3(1)*f*r_csi(-3)
ll1.append sig2 = (omega(1)+alpha(1)*res(-1)^2 +beta(1)*sig2(-1)+gamma(1)*`res(-1)^2*(res(-1)<0))*(1+dum(1)*f)
ll1.append z = res/@sqrt(sig2)
ll1.append logl = log(@dnorm(z)) - log(sig2)/2
' estimate and display output
smpl s2
ll1.ml(showopts, m=1000, c=1e-5,b,h)
show ll1.output
Thanks
Who is online
Users browsing this forum: No registered users and 2 guests
