Hello R-list-members,
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?

Many thanks,
Desislava Kavrakova


Code:

garch<-function(x){
x<<-ts(x)
n<-length(x)

Mean = mean(x); Var = var(x); S = 1e-6
param = c(a = Mean, b1 = S, b2 = S, alpha0 = 0.1*Var,alpha = 0.1, beta = 0.8)
lowerB = c(a = -10*abs(Mean), b1 = S-1, b2 = S-1, alpha0 = S^2, alpha = S, beta 
= S)
upperB = c(a = 10*abs(Mean), b1 = 1-S, b2 = 1-S, alpha0 = 100*Var, alpha = 1-S, 
beta = 1-S)

llh<-function(p){
a<-p[1]
b1<-p[2]
b2<-p[3]
alpha0<-p[4]
alpha<-p[5]
beta<-p[6]

res<-array(length(x))
hh<-array(length(x))
res[1]<-x[1]-a
res[2]<-x[2]-a-b1*res[1]
for (i in 3:n){
res[i]<-x[i]-a-b1*res[i-1]-b2*res[i-2]
}
res<-ts(res)
hh[1]<-alpha0
for (i in 2:n){
hh[i]<-alpha0+alpha*res[i-1]^2+beta*(hh[i-1]-alpha0)
}
hh<-ts(hh)
h<-sqrt(abs(hh))
 
-sum(log(dnorm(x=res/h)/h))
}

fit<-nlminb(param, llh, lower=lowerB, upper=upperB)
fit$par
}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to