[R] Estimation of an GARCH model with conditional skewness and kurtosis

Yohan Chalabi chalabi at phys.ethz.ch
Wed Feb 16 08:46:47 CET 2011


>>>> "JL" == Johannes Lips <johannes.lips at googlemail.com>
>>>> on Tue, 15 Feb 2011 16:07:50 +0100

   JL> Hello,
   JL>
   JL> I'm quite new to R but tried to learn as much as possible in
   JL> the last
   JL> few months.
   JL> My problem is that I would like to estimate the model of Leon
   JL> et al. (2005).
   JL> I have shortly summarised the most important equations in
   JL> the following
   JL> pdf file:
   JL> http://hannes.fedorapeople.org/leon2005.pdf
   JL>
   JL> My main question is now how could I introduce these two
   JL> additional terms
   JL> into the Likelihood function of a(n) (existing) GARCH method.
   JL>
   JL> I looked into some GARCH packages but wasn't really sure where
   JL> to start.
   JL> I know that this is not really an easy task but I would be
   JL> very grateful
   JL> if you could help me out by giving me some hints on how to
   JL> solve this
   JL> problem.
   JL>
   JL> Thanks in advance!
   JL>
   JL> Johannes Lips


Hi Johannes,

You can start by implementing the simple GARCH(1,1) and then modify the
objective function to your needs. You might want to add further
constraints on the parameters.

# ------------------------------------------------------------------------------
# load fGarch and a data set
# ------------------------------------------------------------------------------

library(fGarch)
data(dem2gbp)
x <- dem2gbp[,1]

# ------------------------------------------------------------------------------
# negative log likelihood function of garch11 with normal innovations
# ------------------------------------------------------------------------------

llhGarch11N <- function(par, x)
{
    mu <- par[1]; omega <- par[2]; alpha <- par[3]; beta <- par[4]
    e <- x - mu
    e2 <- e^2

    ##       slow loop
    #        s2 = omega + alpha*mean(e2) + beta*mean(e2)
    #        for ( t in 2:length(x))
    #            s2[t] = omega + alpha*e2[t-1] + beta*s2[t-1]

    #        fast filter
    e2t <- omega + alpha*c(mean(e2),e2[-length(x)])
    s2 <- filter(e2t, beta, "recursive", init = mean(e2))

    
    -sum(log(dnorm(e, mean = 0, sd = sqrt(abs(s2)))))
}

# test llhGarch11N
mu <- mean(x); omega <- 0.1*var(x); alpha <- 0.1; beta <- 0.8
parN <- c(mu, omega, alpha, beta)
llhGarch11N(parN, x)

# ------------------------------------------------------------------------------
# Fit parameters
# ------------------------------------------------------------------------------

small <- 1e-6
lowN <- c(-10*abs(mu), small, small, small)
upN <- c(10*abs(mu), 100*abs(mu), 1-small, 1-small)
fitN <- nlminb(star=parN, objective=llhGarch11N, x = x, lower=lowN, upper=upN,
               control=list(x.tol = 1e-8,trace=1))
fitN$par <- round(fitN$par,6)
names(fitN$par) <- c("mu", "omega", "alpha", "beta")
fitN

# ------------------------------------------------------------------------------
# compare with garchFit
# ------------------------------------------------------------------------------

garchFit(~garch(1,1), x)


# ------------------------------------------------------------------------------


HTH,
Yohan

-- 
PhD candidate
Swiss Federal Institute of Technology
Zurich

www.ethz.ch



More information about the R-help mailing list