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

From: saikat sarkar <dipa_sanyal_at_yahoo.com>
Date: Fri, 04 Apr 2008 13:23:12 -0700 (PDT)

If I understand correct then

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

{

T<-length(y)
mu0<-par
a0<-par
a1<-par
a2 <-par
b1 <- par

e <- s2 <- numeric(T)
s2 <- var(y)
e <- y-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
> http://www.R-project.org/posting-guide.html
>

```--
View this message in context: http://www.nabble.com/Re%3A-how-to-fit-GJR-GARCH-model-in-R-tp4207387p16498300.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help