# [R] how to fit GJR-GARCH model in R

saikat sarkar dipa_sanyal at yahoo.com
Fri Apr 4 22:23:12 CEST 2008

```If I understand correct then

garch.gjr <- function(par,y,iterate=TRUE)

{

T<-length(y)
mu0<-par[1]
a0<-par[2]
a1<-par[3]
a2 <-par[4]
b1 <- par[5]

e <- s2 <- numeric(T)
s2[1] <- var(y)
e[1] <- y[1]-mu0
l<-0

for(t in 2:T)
{
e[t] <- y[t]-mu0
s2[t] <- a0+a1*e[t-1]^2+b1*s2[t-1] + ifelse(e[t-1]<0, a2*e[t-1]^2, 0)
l <- l -0.5*log(2*pi*s2[t])-0.5*e[t]^2/s2[t]

if(s2[t]>10000) return(10000)

}

if(iterate) return(-l)
else return(list(loglik=l,sig2=s2,res=e/sqrt(s2)))
}

y<-data
par0<-c(0,0.038,0.051,0.058,0.991)
# you need to put good initial parameter values
a<-nlm(garch.gjr,par0,y=y,hessian=TRUE)
se <- sqrt(diag(solve(a\$hessian)))

Fan Steven wrote:
>
> Hi,All,
>
> I am trying to fit a GJR-GARCH model in R:
>
> r_t = mu + e_t
> h_t = alp_0 + alp_1 * e_(t-1)^2 + alp_2 * s_(t-1) * e_(t-1)^2 + beta *
> h_(t-1)
>
> where r_t = return (on day t), h_t = conditional volatility on day t,
> and s_(t-1) = 1 if e_(t-1) < 0 (zero otherwise).
>
> I have downloaded the packages "tseries" and "fSeries" but can not see
> how to fit this model.
>
> Any help would be very much appreciated.
>
> Thanks,
>
> Steven
>
> _________________________________________________________________
> 享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help