View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Kalman Filter Application Vasicek

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 2.88 KB File ID: #27685 Version: 1.0

Kalman Filter Application Vasicek



Estimates the parameters of the Vasicek model on a generated term structure

| Watch this File

File Information

3 .m files, 1) simulates a term structure using the vasicek model, 2-3) take this simulation and estimates the parameters of the model.

If the implementation is good, the inputs should equal the outputs, run this 200 times.

For details see;
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.

Please comment or leave suggestions.


Kalman Filter Application inspired this file.

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 (5)
07 Aug 2012 Ka Kit

Ka Kit (view profile)

Hi Nils,
The logic of your program is very clear but I still have few questions. Hope you can give me some hints.

1. Why did you use VarY in step 5 but not the variance of the short rate?

2. In eqn c.11, why the first term is missed comparing to the eqn.76 in the paper?

3. How did you deal with the R matrix?

Do you have an updated file? If yes, could you upload the file or send a copy to me?

Thanks in advance!

Comment only
17 Aug 2010 Christian

Dear Nils,

Thank you for uploading this very well documented .m file!

I got a question concerning LLoneVasicek.m Step 1:
Why do you define Q in the CIR distribution (namely: Q=theta*sigma*sigma*(1-exp(-kappa*dt))^2/(2*kappa)+sigma*sigma/kappa*(exp(-kappa*dt)-exp(-2*kappa*dt))*AdjS; ) instead of using the Vasicek distributed term (namely: Q=[(sigma1*sigma1*(1-exp(-2*kappa1*dt))/(2*kappa1); ) see Bolder(2001) Page30 equations (63)?

I currently work on a Kalman Filter Application for a (correlated) multifactor Vasicek Model. Have you got any experiences with that kind of implementation?

Kind regards,


Comment only
10 Aug 2010 Gammateur frelet

Ok thanks for your explanation. I did not notice the negative sign. Another question, why do you skip the step 2 and 3 (bank of canada's paper) at the begining of your loop ? Should'not you begin with :


for i=1:nrow
% Step 2
PredY=A+H*PredS; % eqn c.4
VarY=H'*VarS*H+R; % eqn c.5
% Step 3
PredError=Y(i,:)-PredY; % eqn c.6
KalmanGain=VarS*H*inv(VarY); % eqn c.8
AdjS=PredS+KalmanGain*PredError'; % eqn c.7
VarS=VarS*(1-KalmanGain*H'); % eqn c.9
% Step 5 Construct the likelihood function
LL(i)=-(ncol/2)*log(2*pi)-0.5*log(DetY)-0.5*PredError*inv(VarY)*PredError'; % eqn c.12

% step 1
PredS=C+F*AdjS; % eqn c.10
Q=theta*sigma*sigma*(1-exp(-kappa*dt))^2/(2*kappa)+sigma*sigma/kappa*(exp(-kappa*dt)-exp(-2*kappa*dt))*AdjS; % eqn b.4
VarS=F*VarS*F'+Q; % eqn c.11

Because we first done an assumption at the begining : E[y1]=E[y1/F0]=[tetha1 thetha2 tetha3]. Excuse me for my bad english.
Thanks a lot

Comment only
09 Aug 2010 Nils Delava

What I do is I minimize the negative likelihood. This is the same as maximizing the likelihood. You will find the negative sign in the code.

I have a different way to implement it in mind at the moment, if I have time I'll do it this weekend as some people have approached me with a similar problem. otherwise I'll take down the files because they are not running smoothly.

Comment only
09 Aug 2010 Gammateur frelet


Thanks a lot for this implementation.

I don't understand why you are using fmincon fonction? Because we have to maximize the likelihood function, not to minimize?

Sometimes, your programs stops with NaN+NaNi for all parameters or shows this message : "Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN. "and is then busy. Do you have this problem ? Thanks a lot.

Comment only

Contact us