1

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!

1 Answers1

1

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) )
Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
  • Thanks for reply! but with the data I want to use for CIR estimation (X2), the estimates' behaviour is wierd. if one varies upper bounds, estimates vary as well. But with X1 they stay stable. What is the way that is used in practice for CIR or CKLS estimations? Thanks – Alexander Kliushnyk Apr 15 '13 at 17:37
  • If you look at the data, you will see two very distinct regimes: you should expect (unreliable estimates and) instability if you change the estimation period. You should separate the pre- and post-crisis periods. In addition, the solution is on the boundary of the domain defined by your constraints, and seems to converge to `(infinity,infinity,0)` if you relax them: if this persists after shrinking the estimation period, the data cannot be modeled by a CIR model, and you should try another model. – Vincent Zoonekynd Apr 15 '13 at 18:07
  • indeed, this crisis time gives so much of disturbances. I ve devided the data into two (pre- and post- crisis) and also have excluded the part of big move downwards and then the estimate are similar when one takes dif-nt windows of 400-600-1000 obs-ns. Thanks! – Alexander Kliushnyk Apr 15 '13 at 18:39