Matlab code - Vasicek yield curve fitting, Various bond price models available

Find it here.

I know there are a couple spelling mistakes... 3 at last count. I found them within minutes of printing it out for submission (4 copies :wall )

I hope its of some help to you.

What exactly are you researching yourself?


you are a star mate, that's really helpful
 
Maximum Likelihood

Thanks a lot for your code. I am also (start) implementing the MLE for Brazilian bonds and testing both Merton and LS models. I can see by reading your previous posts that I have read many papers that you use in your dissertation. That is great to me to see that I am probably reading the most relevant papers. If you have a matlab example with the MLE estimation for Merton model I would be very grateful if you could share it.

Best Regards,

David Favaro.
 
fairly sure if you look through the thesis paper, the code should be included at the end.

i dont know that everything is included, i have a feeling that some of my files were missed out during the copy&paste-a-thon to get all the code in the appendices, but it should be enough to give you some ideas.

i'm afraid to open the thesis again, to look at the code, because i remember thinking "I'll tidy that up later, when i have some free time..." - which might possibly make me the silliest masters research student of all time....
 
I am totally new in this field. I just start learning term structure modeling with Vacisek model. I am now trying to run the model. I just wonder that if the input data is interbank interest rates, the output of term structure obtained from the model could be understood as theoretical zero-coupon yield curve or not? And if it is the theoretical zero-coupon yield curve, I have to construct the observed zero-coupon yield curve to determine the accuracy of the model but unfortunately it is nearly impossible in my case. So how do I know the model is accurate or not?
Could you talented guys instruct me? I am really confused with the input data and output term structure of Vasicek model as mentioned about.
Thank you very much.
 
Sorry, can you possibly explain in a bit more detail, and a little clearer, exactly what you are trying to do, and what problems you currently have. I'll try to help if i can.
 
Sorry if I could not express my problem clearly enough.

I have the real data of interbank rates at daily and monthly frequency. I tried to use those set of data to find out the optimal parameters of Vasicek model. I got the parameters.

The next step is to construct the term structure. Here I am confused. I used the parameters obtained from the previous step in order to derive A(t,T), B(t,T), P(t,T) and finally the yield R(t,T). As I understand the yield R(t,T) is the spot yield or zero-coupon yield. My question is why the input is interbank rates, the output could be zero-coupon yields? In my case, I could not collect the observed zero-coupon yields matured in one day as in your thesis, so I have to use interbank rates as input.

I also read your thesis. Thank you very much for your share. I really appreciate your work. However, in your case, the data of an observed zero-coupon curve is available and you can compare the observed curve with the theoretical curve from Vasicek to assess the accuracy of the model.
In my case, it is nearly possible to get an observed curve. How can I compare?

 
If possibly, could you talented guys give me some instructions about steps to conduct empirical study on Vasicek model, particularly the input data needed, the implementation of the output term structure. Precisely, I am now learning by myself how to estimate term structure with Vasicek model and interpret the obtained results.
Thank you.
 
thank you very much for your reply. i have seen the program " YieldCurveFitVasicek". this program as i have understood estiamte the paremeters of the short term interest rate process (theta; kappa;and eta) by fitting the vasicek model to the market data.
But im my research i have estimated these parameters by the GMM method and still only the market price of risk lamda to estimate by fitting the interest rate term structure of the vasicek model to the observed interest rate term structure. can you please tell me how can i do it. Thank you.
I have a similar problem. I'm working with the Ahn-Gao (1999) one factor short-rate model and I have estimated the parameters of the process under the REAL measure (kappa,theta,sigma) via GMM using time series data from Libor market assuming the one month Libor rate as a proxy for the instantaneous rate (daily observations). I used the Mike Cliff library for GMM estimation. Now, I have to calibrate the model under the RISK NEUTRAL measure in order to estimate the market price of risk (two parameters lambda1and lambda2) by minimizing the squared deviations between model yields and market yields. Can I use the Matlab codes for Vasicek yield curve fitting, modifying the code or is not appropriate? I want to modify the code in such a way that I can pass the estimated parameters (k,theta,sigma) as input for the discount function and then perform the minimization regarding the discount function as a function of only lambda1 and lambda2. Any suggestions?
Thanks.
 
Hi all

Just finished my masters, and have a bit of code sitting around which I used in my thesis in case anyone wants it. Everything is in Matlab.

I was working on a project trying various structural bond pricing models to price corporate bonds, and implemented the Merton 1974, Longstaff and Schwartz 1995, and Briys and de Varenne 1997 models, as well as the Vasicek 1977 risk-free bond model.

In addition, and as a requirement for some of the above models, I wrote some code to fit the Vasicek interest rate process to an observed term structure (yield curve) and thereby allow you to retrieve the parameters which when fed into the Vasicek model will result in the observed structure.

I was going to post the code on the Mathworks community site, but its been redesigned and seems really painful now :(

I owe a debt of thanks to a German guy who sent me some R code upon which showed the term structure modelling idea being applied, as per the papers of Eom, Huang and Helwege 2004, so I figured I'd try to give something back. If anyone wants any of the above code, just message me to let me know. It should be easily readable and adaptable I'd think.

Anyway, if the above makes sense and the code will be of any use to anyone, let me know.

Hi Johnathan,
I need your codes urgently and i will also like to pick on your brains. I am currently doing my dissertation on bond and want to be doing something along your line. my email address is natonolives@yahoo.com.
I hope to hear from you as soon as possible
 
Hi, I have a question about Vasicek's model. I've already estimated the parameters: pull-back, long term mean, and sigma, using MLE method. But I'm not sure how to go from there: how exactly should I reconstruct the yield curve based on the simulated rates and bond pricing formula?

The bond pricing formula is P[t,T] = Exp[A(t,T) - r B(t,T)]. And we know the relationship b/t the price and yield: Y = -Log[P]/(T-t).
What I'm doing is using the yield formula to fit in the current yield curve to get the parameters, and then sub in my simulated short rates. So each simulation will produce different yield curve, as expected because the simulated rates will be different. However, my problem is the there is not so much variability of my simulated yield curve.

Can anybody help? I'm afraid that I should not have used Y = -Log[P]/(T-t) to fit in the current yield curve. People have been saying using zeros price to fit the yield curve, but the P[t,T] is price, not yield.
 
Mego: First, I would suggest that posting your question multiple times in different threads is generally frowned upon. Spamming the forum won't earn you much respect.

Second, you don't really explain what you are trying to do, or why. You state that "my problem is there is not so much variability of the simulated curve", but you don't explain why this is a problem. Are you trying to simulate a time series using the Vasicek model? Why do you need varied curves? Do you mean that your estimated volatility parameter is very low, and so you don't experience much randomness when you simulate the time series?
 
Mego: First, I would suggest that posting your question multiple times in different threads is generally frowned upon. Spamming the forum won't earn you much respect.

Second, you don't really explain what you are trying to do, or why. You state that "my problem is there is not so much variability of the simulated curve", but you don't explain why this is a problem. Are you trying to simulate a time series using the Vasicek model? Why do you need varied curves? Do you mean that your estimated volatility parameter is very low, and so you don't experience much randomness when you simulate the time series?

Hi,thanks for your reply. I was new to this forum, and I posted the same message twice simply because soon after I posted there, I realized that I probably should have started a new thread.

I'm valuing interest rate swaps, so essentially I have to simulate future short rates for discounting purpose. I have to simulate yield curve at each point in time, and discount all future cash flows to that point based on the simulated yield curve. I used the US historical overnight rates to estimate the 3 parameters: pull-back, long term mean, and sigma ( I call this the first set of parameter). Then I used Y(r, t,T) = -Log(P[t,T])/(T-t) to do the yield curve fitting, and I got the second set of parameters: a, b, sigma (those are the parameters in the bond pricing formulas). I thought the second set of parameters are different from the ones in Vasicek's short rate model - the first set of parameters were estimated from historical overnight rates; second set was estimated from the current market yield curve (swap curve).Note, at this point, I have a function Y(r,t,T), t is always equal to zero because yield curve starts at time zero. r will be replaced by my simulated short rates(overnight rates), then if I vary T from zero to 30 yrs, then I have one simulated yield curve. To obtain another simulated curve, I only have to sub in a new simulated short rate r.

May be the lack of variability is not the issue, but I just wondered if my process is correct. Thanks.
 
From the way I read your explanation, I think what you're doing makes sense... if you check out my thesis at the start of this thread, I do something similar I believe... fit a term structure to get the implied vasicek params, and then feed them into various bond pricing formulas.
I dont see any reason to wish your yield curves that are generated to be wildly varied... if the input variables are similar the results would be similar, no?
 
From the way I read your explanation, I think what you're doing makes sense... if you check out my thesis at the start of this thread, I do something similar I believe... fit a term structure to get the implied vasicek params, and then feed them into various bond pricing formulas.
I dont see any reason to wish your yield curves that are generated to be wildly varied... if the input variables are similar the results would be similar, no?
Don't know how to address you, but anyway your inputs are highly appreciated! I just bought two books, should have them today.
Efficient Methods for Valuing Interest Rate Derivatives, Antoon Pelsser Interest Rate Models - Theory and Practice: With Smile, Inflation and Credit (Springer Finance), Damiano Brigo, Fabio Mercurio

Have you started your quant career yet?
 
Dale is fine. As for quant career, yeah, I've made the jump from an analyst/programmer career, into quant finance, as of a couple years ago.

That interest rate models book by Brigo/Merc is quite well regarded I think, I've used it a few times. But i think you will find it theoretically detailed, but possibly not very useful for actual implementations. I've found it hard to find good books that tell you "this is how you ACTUALLY implement these ideas", one of Paul Wilmotts "intro to quant fin" books is probably one the most rough-and-ready ones that I've seen.

Good luck.
 
Hi!

The Vasicek code works great! I was just wondering if it is possible to use this code for the CIR (Cox Ingersoll Ross) model as well? By just changing the bond pricing formulas to the ones according to the CIR-model?
 
I havent looked at the code for quite a while, but I think the optimisation should work in a similar way, yes. That is, if you change the pricing formulas, the seeking algorithm should find the optimal parameters to fit your curves etc. Good Luck.
 
I havent looked at the code for quite a while, but I think the optimisation should work in a similar way, yes. That is, if you change the pricing formulas, the seeking algorithm should find the optimal parameters to fit your curves etc. Good Luck.

Yes, that is my idea too. It should be able to use the same optimization, but changing the bond pricing formulas. But right now I get weird results. I'll try some more. Probably just a minor mistake somewere in my code.

Thanks anyway for the answer!
 
Back
Top Bottom