Hi,
As far as I can tell, your code looks very similar to the example of
the paper "Parameter Estimation of ARMA Models with GARCH/APARCH
Errors" available at the rmetrics website. In this paper you can also
find an example how to calculate the hessian matrix.
What is the dataset and the parameters you are trying to estimate?
regards,
Yohan
regards,
Yohan
>>>> "DK" == Desislava Kavrakova <dkavrakova at
yahoo.com>
>>>> on Mon, 18 Aug 2008 02:03:05 -0700 (PDT)
DK> Hello R-list-members,
DK> I'm trying to model ARMA(0,2) & GARCH(1,1) process using the
code below, but according to my textbook, the estimated parameters are wrong.
The MA-parameters should be negative. (I've got the same problem using
garchFit()). Can anyone tell me what I'm doing wrong? And how can I
calculate the hessian matrix?
DK>
DK> Many thanks,
DK> Desislava Kavrakova
DK>
DK>
DK> Code:
DK>
DK> garch<-function(x){
DK> x<<-ts(x)
DK> n<-length(x)
DK>
DK> Mean = mean(x); Var = var(x); S = 1e-6
DK> param = c(a = Mean, b1 = S, b2 = S, alpha0 = 0.1*Var,alpha = 0.1, beta
= 0.8)
DK> lowerB = c(a = -10*abs(Mean), b1 = S-1, b2 = S-1, alpha0 = S^2, alpha
= S, beta = S)
DK> upperB = c(a = 10*abs(Mean), b1 = 1-S, b2 = 1-S, alpha0 = 100*Var,
alpha = 1-S, beta = 1-S)
DK>
DK> llh<-function(p){
DK> a<-p[1]
DK> b1<-p[2]
DK> b2<-p[3]
DK> alpha0<-p[4]
DK> alpha<-p[5]
DK> beta<-p[6]
DK>
DK> res<-array(length(x))
DK> hh<-array(length(x))
DK> res[1]<-x[1]-a
DK> res[2]<-x[2]-a-b1*res[1]
DK> for (i in 3:n){
DK> res[i]<-x[i]-a-b1*res[i-1]-b2*res[i-2]
DK> }
DK> res<-ts(res)
DK> hh[1]<-alpha0
DK> for (i in 2:n){
DK> hh[i]<-alpha0+alpha*res[i-1]^2+beta*(hh[i-1]-alpha0)
DK> }
DK> hh<-ts(hh)
DK> h<-sqrt(abs(hh))
DK>
DK> -sum(log(dnorm(x=res/h)/h))
DK> }
DK>
DK> fit<-nlminb(param, llh, lower=lowerB, upper=upperB)
DK> fit$par
DK> }
--
PhD student
Swiss Federal Institute of Technology
Zurich
www.ethz.ch