1

我想通过 R 中的 ML 来估计 CIR 模型参数。它如下所示:

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

该方法在 Iacus 的书“Option Pricing and Estimation of Financial Models with R”附带的 sde packege 中实现。

在那里,在示例(第 5 章)中,实现了速率估计并计算了系数 theta1-3。现在我想用我的数据集(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))

我将非常感谢任何帮助!

4

1 回答 1

1

在 CIR 模型中,该比率几乎肯定是非零的:去除负值是不够的。

# 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) )
于 2013-04-15T14:27:31.653 回答