5.0

5.0 | 1 rating Rate this file 25 Downloads (last 30 days) File Size: 39.8 KB File ID: #27705

Kalman Filter Application two factor CIR

by

 

Estimates the parameters of the two factor CIR model on the UK German, and US term structures.

| Watch this File

File Information
Description

2 .m files, 3 xls files with data from German, US, UK zero coupon bonds.
Files estimate the parameters on these bonds, the optimizer doesn't really work that well for this problem, so if some-one has a solution, please let me know.

For details of methodology see;

http://www.bankofcanada.ca/en/res/wp/2001/wp01-15a.pdf
and/or
Ren-Raw Chen and Louis Scott, “Multi-Factor Cox-Ingersoll-Ross Models of the Term Structure: Estimates and Tests from a Kalman Filter Model,” The Journal of Real Estate Finance and Economics 27, no. 2 (2003): 143-172.
etc.

Please comment or leave suggestions.

thanks Bill, 27493

Acknowledgements

Kalman Filter Application inspired this file.

Required Products xPC Target Embedded Option
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
14 Aug 2011 ben salah

how can i run this code?

01 Aug 2011 Steve G

I believe there is another problem in the code, LLtwoCIR, in the calculation of the Q matrix, the (1,1) element of which is,
(theta1*sigma1*sigma1*(1-exp(-kappa1*dt))^2/(2*kappa1)+sigma1*sigma1/kappa1*(exp(-kappa1*dt)-exp(-2*kappa1*dt)))*AdjS(1)
I think the correct code is,
theta1*sigma1*sigma1*(1-exp(-kappa1*dt))^2/(2*kappa1)+sigma1*sigma1/kappa1*(exp(-kappa1*dt)-exp(-2*kappa1*dt))*AdjS(1)
The AdjS only multiplies the second term, not both the first and second, see Chen and Scott (2003), page 147, second formula.
Thanks

29 Jul 2011 Steve G

I like the simple code, however I donot understand the following code segment:
VarS=VarS*(1-KalmanGain*H);
Given the KalmanGain definition:
KalmanGain=VarS*H'*InvVarY;
The above VarS is not symmetric, and (1-KalmanGain*H) is not correct either. I believe the corrrect calculation should be:
VarS=(eye(2)-KalmanGain*H)*VarS;

Comment? Thanks.
Steve

24 Aug 2010 luisa cutillo

I am trying to replicate your results but the code as it is produces errors in the optimization part and it stops around the 50th iteration. The final mean values are very far from the true one. Moreover the numbers that I am getting are very far from the ones in CIR200.mat. Can you please help? I am just running your code as it is with matlab 2008. Thanks in advance. Luisa.

17 Aug 2010 Christian

Dear Nils, dear Yan,

How do these optimizer tricks look like? I currently work on a Kalman Filter Application for a (correlated) multifactor Vasicek Model, which has got even more parameters to optimize and I am afraid the optimizer will stuck.

Thanks in advance,

Christian

15 Aug 2010 Qinyu Yu

Hi Hils, thank you for your answer.
I have another question, what does the "sigmai" stand for? Is that represent to the variances of measurement errors? But why does it can be negative? could you tell me what is the definition of this paremeter? Thank you very much!

The location of this parameter as follows:
% Initialize the parameters for CIR model
theta1=para(1);
kappa1=para(2);
sigma1=para(3);
lambda1=para(4);
theta2=para(5);
kappa2=para(6);
sigma2=para(7);
lambda2=para(8);
sigmai=para(9:end);

R=eye(ncol);
for i=1:ncol
R(i,i)=sigmai(i)^2;
end

08 Aug 2010 Nils Delava

the initial parameters are decided with a little trial and error and some common sense. In the files I've set them as the answer because then the optimizer works better, but you are right it does not run smoothly. There is some common sense aswell, if you "surf()" the historic term structure you can see that it is always upward sloping so the risk aversion coeff. will be negative, etc.

Also the papers I've cited in the description gives some indication.

I also played around a bit with the other optimizers such as patternsearch and fmin.

When I have some time i will re-do them, as I don't think that the measurement errors (the other sigma's) should be in the optimizer. I think they should be 0.005*randn() and then resample (run the optimiser) 100 times or so to get 100 answers (slightly different) and then take the mean of that.

03 Aug 2010 Salim

Hi Nils, Yan,

I am working on the CIR calibration using a Kalman filter. How do you make the optimization work? Sometimes, the fmincon function generates a warning of the form: "Matrix is close to singular or badly scaled. Results may be inaccurate". Have you found a way around that? Yan, how have you solved the optimization problem in general?

Thanks guys

30 Jul 2010 Qinyu Yu

Hi Hils, could you tell me how did you decide the initial parameter value as input ? Thank you very much!

06 Jul 2010 Nils Delava

sent you email

29 Jun 2010 Yan Du

Hi Nils, i was able to make the optimizer work by using some tricks. However, I would like to know how would you decide the initial parameter value as input ?

Contact us