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!
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?
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 :
% 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
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.
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.