[R-SIG-Finance] about Nelson-Siegel model fitting

Brian G. Peterson brian at braverock.com
Sat Mar 13 13:33:31 CET 2010


Yin ZHANG wrote:
> What I have: traded bond prices, along with their coupon/maturity
> sprcifications
 >
> What I want to do: get the NelsonSiegel parameters for the fitted yield
> curve
> 
> What I am doing:
> 
> 1. I use the fixed income toolbox within Matlab 2008b to get the fitted
> curve data( it only provides the curve, but no NelsonSiegel parameters).
> i.e., Matlab only outputs the spot/forward yield you want in certain
> maturities.

As I told you before, the spot yield on a bond, given it's observed price and 
known maturity, is simple algebra.  R can do this easily, with or without the 
aid of a package.  You don't need a 'toolbox' to calculate these things, or to 
graph the resulting yield curve, fitted or not.  There are tools for doing this 
(see below) if you want them.

(there's absolutely no point in fitting a yield curve at this stage if the 
output of the fitted model isn't what you want)

You aren't going to get past the step of converting spot prices to yields on 
each series.  You have to do it to get what you want.  Write a function, make 
it easily repeatable, or use one of the packages.

> 2.Then I use the fBonds package function NelsonSiegel function to get the
> parameters of the Nelson Siegel Model.

The input to every Nelson Siegel method that I'm aware of is a set of spot 
yields and maturities. The output is a fitted yield curve and the parameters of 
the stochastic term structure model.


The packages I'm aware of for doing all this in R are

'YieldCurve', which I mentioned in my previous email.

'fBonds' which you are already familiar with.

'RQuantLib' which as discussed only returns the fitted curve, and

'termstrc' which contains a setting for using *prices* to calculate the yield 
and then fit the model.
http://cran.r-project.org/web/packages/termstrc/index.html
http://r-forge.r-project.org/projects/termstrc/

The only thing I can think of is that you haven't tried termstrc, otherwise I'm 
not sure what you've done here except to re-ask the same question.

In the interests of exposition and to aid future searches, all of these 
packages are mentioned in the CRAN Finance Task View:

http://cran.r-project.org/web/views/Finance.html

Regards,

   - Brian

> On Mon, Mar 8, 2010 at 4:56 AM, Khanh Nguyen <knguyen at cs.umb.edu> wrote:
> 
>> FittedBondCurve only returns curve data, you can not get the
>> parameters of the model.
>>
>> -k
>>
>>> I am wondering whether I can get the parameters of the Nelson-Siegel
>> model
>>> directly from this FittedBondCurve method.
>>>
>>> Also, if possible, could you kindly provide a specific example for the
>>> following bonds price dataset that I have attached with this mail?
>>>
>>> My primary aim is to get the Nelson-Siegel model parameters. Also, I want
>>> pricing errors of the fitted curve, such as sum of price errors squared.
>>>
>>> Thanks a lot in advance.
>>>
>>> Kindest
>>>
>>> Yin
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Mar 6, 2010 at 9:58 PM, Khanh Nguyen <knguyen at cs.umb.edu> wrote:
>>>> You can look into RQuantLib
>>>>
>>>> -k
>>>>
>>>> On Sat, Mar 6, 2010 at 8:23 AM, Yin ZHANG <fly1985 at gmail.com> wrote:
>>>>> I am trying to fit the bond market data to the Nelson-Siegel term
>>>>> structure
>>>>> model. I have a series of bond price data, most of them are coupon
>>>>> bonds.
>>>>> According to the original Nelson-Siegel model setting, my objective is
>>>>> trying to get the paremeters that minimize the weighted/unweighted
>>  sum
>>>>> of
>>>>> price errors squared.
>>>>>
>>>>> So, is there any simple way in R or any package that can do this job?
>> I
>>>>> do
>>>>> not know any about non-linear optimization, so what I need is an easy
>> to
>>>>> use
>>>>> package/code that can do the job.
>>>>>
>>>>>
>>>>> thanks a lot in advance.
>>>>>
>>>>>
>>>>> Yin
>>>>>
>>>>>        [[alternative HTML version deleted]]
>>>>>
>>>>> _______________________________________________
>>>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>>>> -- Also note that this is not the r-help list where general R
>> questions
>>>>> should go.
>>>>>
>>>
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.


-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list