[R] maximum likelihood
Jurica Brajković
jbrajkovic at eihp.hr
Fri Sep 26 08:01:31 CEST 2008
Hello,
I am trying to estimate parameters of mean reverting process with jumps given by: dp=k(mu-p)dt+sigma*dz+Jdq where dp represents change in log of price, k is reversion factor, mu is long run level of price, sigma is standard deviation, and dq equals one with probability lambda if jump occurs and 1-lambda otherwise. J is jump size with mean muj and standard deviation delta. Therefore, when there is no jump, mean of the distribution is just expected value of mean reverting process which in this case is E(p(t))=b0+b1*p(t-1) because it can be written as AR(1) with standard deviation equal to sigma. When jump occurs, mean is equal to b0+b1*p(t-1)+muj and standard deviation is equal to sqrt(sigma^2+delta^2)
The code I use is:
p<-matrix(data$p) # price at time t
lp<-cbind(1,data$lp) # price at time t-1
mle <- function(theta) {
sigma<-theta[1]
delta<-theta[2]
lambda<-theta[3]
muj<-theta[4]
b<- theta[5:6]
e<-lp%*%b
#I have omitted 2pi from likelihood function
logl<- sum(log(
(((1-lambda)/sigma)*exp(-t(p-e)%*%(p-e)))/(2*sigma^2)+((lambda)/sqrt(sigma^2+delta^2))*exp(-t(p-e-muj)%*%(p-e-muj))/(2*((delta^2+sigma^2))))
)
return(-logl)
}
out <- optim(c(1,1,1,1,1,1),fn=mle, method = "BFGS")
Unfortunately I get the error that “Error in optim(c(1, 1, 1, 1, 1, 1), fn = mle, method = "BFGS") : initial value in 'vmmin' is not finite”
Can someone help.
Thanks,
Jurica Brajkovic
More information about the R-help
mailing list