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

daleholborow

Active Member
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.
 

daleholborow

Active Member
The R code for the Vasicek parameter finding should be available if you search for posts made by a user named "cyklop", in the wilmott forums.

Attached is my matlab code and what I believe are all the necessary files to run the functions. Sometimes my commenting is overkill, and sometimes its stating the obvious, but on the whole, if you are trying to get any of these models working, it should be a good start to work from.

Note that I coded up the Longstaff and Schwartz bond model according to their original specification, in contrast to a newer model as used by Li and Wong in their 2008 paper regarding Maximum Likelihood Estimation of bond parameters (which was the focus of my thesis). The Briys and De Varenne model is also coded differently to how the equation is specified, but where the original equation was written recurcisively, this method is exponentially faster and still produces correct results (as matched to their 1997 paper).

If you want to find parameters for a Nelson and Siegel interest rate model based on a daily term structure observation, you'll find code for that on the Matlab community forum, here:

MATLAB Central - Files

I have a massively large body of code that implements the MLE for the Merton and LS models parameters based on the paper of Li&Wong ("Structural models of corporate bond pricing with maximum likelihood estimation.") and earlier, on a paper by Duan in 1995 and 2003, but its fairly specific to my own project and I doubt would be of any use to anyone in its current form.

That said, if any of you are doing research on structural bond pricing models using MLE, I might be able to offer you some advice.

And briefly, that advice goes like this: Don't bothe, they don't work ;)

Good luck
 

Attachments

mouna

New Member
please can you post the matlab code here. i need it. i will be very grateful. Thank you very much .
 

mouna

New Member
i want to estimate the market price of risk of the interest rate term structure l, for the vasicek(1979), Cox Ingersoll and Ross (1985) and CKLS (1992) models by minimizing the deviation of the implied yield curve from the average zero-coupon yield over the sample. please can you provide me with the matlab code that do it.
 

mouna

New Member
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.
 

daleholborow

Active Member
hmm, not exactly sure I entirely understand what you are trying to do. You've already established interest rate parameters for the Vasicek model, is that correct?

Not sure that I'll be able to help you out much more than that anyway, my research project was very large and I didn't do much work purely for the sake of interest, if that work was outside the scope of my project because I didn't have time...
 

Claus

New Member
What real-life data should I use

Hi everyone. I have more or less an ok idea of the theory of modelling the interest rate, but now I need to do calibration and subsequently simulations, and I dont know what REAL data I should get? I have access to Thomsons Datastream, but what kind of data should I look for?

Thanks for your help

Claus
 

daleholborow

Active Member
Claus... in Datastream, you should be able to do a search for interest rate data, in the same way that you search for bonds or equity/option prices etc. For example, there will be US treasury yield curve values, all listed as instruments of different maturities. Eg, the code will be something like US0Y01M for a one month yield, US0Y2M for a two month yield, etc, from memory.

Now, depending on how you wish to do your interes rate modelling, you might need either a term structure observation (so, for any given date, you then retrieve the yield curve by getting the 1m, 2m, 3m, .... , 1y, 2y, 5y, 10y etc yield values), which is what _I_ did to fit the Vasicek interest rate model.

Alternatively, you can take some instrument, say the 1m treasury yield, and take its values over a long date range... say the year 2008, and then perform some time series analysis to get your interest rate parameters.

If you need to do "calibration and simulations", to me at least, it sounds like you need to go with the second approach. If i can find some papers on the topic, I will post them here. Good luck.
 

wisnu

New Member
Code Inqury

Dear Sir,

I also plan to conduct thesis on bond area. So your formula will really valuable for me.
Thank you for your kindest assistance.

Warm regards,
Wisnu
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.
 

daleholborow

Active Member
no worries, i hope you can get something useful out of the code :)

i'd tried to do a couple others, like the colin-dufresne and goldstein, but ran out of time unfortunately. I really should subscribe to a couple journals and do some research again...
 

kartt

New Member
Buddy ,thanks for the code.
can u please post the matlab code to estimate the parameters fro Nelson seigal interest rate model?
 

gigiquant

New Member
Hi,

Thanks nice code,
do you mind providing also a copy of your thesis?

thanks,
Gigi


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.
 

daleholborow

Active Member
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?
 

Attachments

johnathan

New Member
hey guys need the MATLAB code for Nelson siegel model for a zero coupon german bond...can anyone help?
 
Top