[R] VECM - GARCH using maxLik()
Philipp Grueber
philipp.grueber at ebs.edu
Wed Feb 9 18:33:12 CET 2011
Hi Arne,
thanks for the quick answer & sorry for the mistake. Please find a corrected
version of the code below. Unfortunately, the model still does not work –
due to an error I believed to have overcome: “In log(2 * pi * sig2[i]) :
NaNs produced”
So my questions remain the same: Why doesn't this work... and how can I
avoid the for-loop?
library(maxLik)
library(fGarch)
lag<-function(x,k){
c(rep(NA,k),x[1:(length(x)-k)])
}
r<- as.vector(garchSim(garchSpec(rseed = 1985), n = 102)[,1])
r_1<- lag(r,1)[4:102]
r_2<-lag(r,2) [4:102]
s<-rnorm(102)
s_1<- lag(s,1)[4:102]
s_2<-lag(s,2) [4:102]
c_1<-s_1-r_1
r <- r[4:102]
s<-s[4:102]
data<-as.matrix(cbind(r,r_1,r_2,s_1,s_2,c_1))
sum(na.omit(data)!=data)
loglik <- function(param) {
res <- param[1]
a0 <- param[2]
a1 <- param[3]
a2 <- param[4]
a3 <- param[5]
a4 <- param[6]
a5 <- param[7]
omega <- param[8]
alpha <- param[9]
beta <- param[10]
res <- r-a0-a1*r_1-a2*r_2-a3*s_1-a4*s_2-a5*c_1
sig2 <- numeric(99)
ll <- numeric(99)
sig2[1] <- 0
for (i in 2:99) {
sig2[i] <- omega + alpha*res[i-1]^2 + beta*sig2[i-1]
ll[i] <- -1/2*log(2*pi*sig2[i]) - 1/2*res[i]^2/sig2[i]
}
ll
}
est <- maxLik(loglik, start=c(.5,.5,.5,.5,.5,.5,.5,.5,.5,.5))
summary(est)
Thank you very much! Best wishes,
Philipp
-----
____________________________________
EBS Universitaet fuer Wirtschaft und Recht
FARE Department
Wiesbaden/ Germany
http://www.ebs.edu/index.php?id=finacc&L=0
--
View this message in context: http://r.789695.n4.nabble.com/VECM-GARCH-using-maxLik-tp3297453p3297757.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list