llikelihood.CIR<-function(theta,kappa,sigma,rt) {
n<-NROW(rt)
dt<-1/12
mu<-rt[1:(n-1),]*exp(-kappa*dt)+theta*(1-exp(-kappa*dt)) #Take prior rates for mu calculation
sd<-sqrt(rt[1:(n-1),]*(sigma^2/kappa)*(exp(-kappa*dt)-exp(-2*kappa*dt))+theta*sigma^2*(1-exp(-kappa*dt))^2/(2*kappa))
-sum(dnorm(rt[2:n,],mu,sd,log=TRUE))
}
theta.est <- 0.04
kappa.est <- 0.5
sigma.est <- 0.02
parameters.est<-c(theta.est,kappa.est,sigma.est)
library(stats4)
bound.lower <-parameters.est*0.1 # set the lower bound for the method "L-BFGS-B"
bound.upper <-parameters.est*2.0 # set the upper bound for the method "L-BFGS-B"
est.mle<-mle(likelihood.CIR, start= list(theta=theta.est,kappa=kappa.est,sigma=sigma.est),method="L-BFGS-B",fixed=list(rt=rt),lower=bound.lower,upper=bound.upper)
summary(est.mle)
---------------
上面的code一直报下面这个错误提示,求高手指导
----------------
Error in if (!all(lower[isfixed] <= fixed[isfixed] & fixed[isfixed] <= :
需要TRUE/FALSE值的地方不可以用缺少值


雷达卡




京公网安备 11010802022788号







