I want to estimate CIR model parameters though ML in R. It looks like following:

dr=(theta1-theta2*r) + theta3*sqrt(r)*dW.

THe method is inplemented in sde packege that accompanies the book of Iacus "Option Pricing and Estimation of Financial Models with R".

There, in the example (ch 5), the estimation of rates is implemented and coefficients theta1-3 are calculated. Now I want to do the same but with my dataset (X2).

library(quantmod)

library(sde)
library(Ecdat)
data(Irates)
X1=Irates[,"r1"]
getSymbols(Symbols="DTB4WK",src="FRED")
X2=interpNA(coredata(DTB4WK))
X2[X2<0]=0

X=X2
CIR.logistic = function(theta1, theta2,theta3) {
  n=length(X)
  dt=deltat(X)
  cat(theta1,"  ",theta2, "  ",theta3,"  \n")
  return(-sum(dcCIR(x=X[2:n],Dt=dt,x0=X[1:(n-1)], theta=c(theta1,theta2,theta3),log=TRUE)))
}
mle(CIR.logistic,start=list(theta1=0.1, theta2=0.1,theta3=0.1),method='L-BFGS-B',
    lower=c(0.01,0.01,0.01),upper=c(1,1,1))

I would very appreciate any help!

有帮助吗?

解决方案

In the CIR model, the rate is almost surely non-zero: removing the negative values is not sufficient.

# Also remove zeroes (if there are many of them, it is probably not a good idea)
X[ X <= 0 ] <- .1

# Then, you code works
mle( CIR.logistic,
     start = list(theta1=0.1, theta2=0.1, theta3=0.1),
     method = 'L-BFGS-B',
     lower = c(0.01,0.01,0.01),
     upper = c(1,1,1) )
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top