我想通过R中的ML来估计CIR模型参数。它看起来如下:
dr =(theta1-theta2 * r)+ theta3 * sqrt(r)* dW。
该方法在sac packege中附带,该书包含在Iacus“期权定价和R评估金融模型”一书中。
在那里,在示例(ch 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))
我非常感谢任何帮助!
答案 0 :(得分: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) )