YieldCurve from discount factors

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

YieldCurve from discount factors

Shuaib Osman
Hi,

Is there any way in quantlib not to create a yieldcurve from ratehelpers (the usual depo/fra/future/swap ones) but instead to import an existing yield curve (a zero curve that starts today and has every point till 20 years from now). I've tried creating deposit rate helpers for each day but I keep getting the "two instruments have the same maturity" error.

So, in short, I've got all the discount factors - I need to create a yieldcurve object.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve from discount factors

javit
Build two vectors of types Rate and Date. Call them dates and rates. Find the rate for that particular date by using your discount curve data. Define a day counter (termStructureDayCounter) and a calendar. Initiate an instant of the termstructure class as below.

        Handle<YieldTermStructure> refTermStructure(boost::shared_ptr<YieldTermStructure>(
                new InterpolatedZeroCurve<LogLinear>(dates, rates, termStructureDayCounter)));

To get your discount rate for a particular date, you can use something like this:

refTermStructure->discount(Date(11,July,2010))

You can also use interpolation methods other than LogLinear. Go through the source code, you will see.

Javit

Shuaib Osman wrote
Hi,

Is there any way in quantlib not to create a yieldcurve from ratehelpers (the usual depo/fra/future/swap ones) but instead to import an existing yield curve (a zero curve that starts today and has every point till 20 years from now). I've tried creating deposit rate helpers for each day but I keep getting the "two instruments have the same maturity" error.

So, in short, I've got all the discount factors - I need to create a yieldcurve object.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve from discount factors

Luigi Ballabio
On Mon, 2009-11-16 at 14:04 -0800, javit wrote:
> Build two vectors of types Rate and Date. Call them dates and rates. Find the
> rate for that particular date by using your discount curve data. Define a
> day counter (termStructureDayCounter) and a calendar. Initiate an instant of
> the termstructure class as below.
>
> Handle<YieldTermStructure>
> refTermStructure(boost::shared_ptr<YieldTermStructure>(
> new InterpolatedZeroCurve<LogLinear>(dates, rates,
> termStructureDayCounter)));

Or use InterpolatedDiscountCurve.

Luigi


--

Ogden's Law:
The sooner you fall behind, the more time you have to catch up.



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve from discount factors

Cliffy
Hi, I am new to quantlib, read this post and out of curiosity want to try it out.
I thought the usage of "InterpolatedDiscountCurve" is to provide a set of "discount factors" and
be able to calculate par rates on the curve.

I use a simple unrealistic discount curve (to 30 days) -

Date Disc factor

Sep 23   1
Oct 1     0.995
Nov 3     0.992

try to calculate par rate as of Oct 1, I got  

0.0050251256281407079

it seemd to be too small, shouldn't be around 20%??

here are the codes,

    vector<Date> dates;
    vector<DiscountFactor> rates;
    vector<Date> datesIn;
         
    DayCounter termStructureDayCounterX = Actual360();;
    Calendar calendarX = TARGET();  

    Date settlementDateX(22, September, 2004);    
    Date d1 = calendarX.advance(settlementDateX, 1,Days);
    dates.push_back(d1);
    d1 = calendarX.advance(settlementDateX, 7,Days);
    dates.push_back(d1);
    d1 = calendarX.advance(settlementDateX, 30,Days);
    dates.push_back(d1);
    Rate r1 = 1;
    rates.push_back(r1);
    r1 = 0.995;
    rates.push_back(r1);
    r1 = 0.992;
    rates.push_back(r1);
       
    Handle<YieldTermStructure> 
    refTermStructure(boost::shared_ptr<YieldTermStructure>(
       new InterpolatedDiscountCurve<LogLinear>(dates, rates,
    termStructureDayCounterX)));
   
    d1 = calendarX.advance(settlementDateX, 1,Days);
    datesIn.push_back(d1);
    d1 = calendarX.advance(settlementDateX, 7,Days);
    datesIn.push_back(d1);

    Rate r2;
    r2 = refTermStructure->parRate(datesIn,Annual,true);

    cout << r2;  // r2 = 0.0050251256281407079

What did I do wrong here??

Regards,

Cliff
 
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve from discount factors

Giorgio Pazmandi
Hi Cliffy, the par rate is calculated in QL with the formula
ParRate = (DF_start - DF_end) / \SUM(DF_i) = (1 - 0.995) / (0.995) =
0.0050251256281407079

Maybe I'm wrong, but I would have expected:
ParRate = (DF_start - DF_end) / \SUM(DF_i * (T_i - T_{i-1})) = (1 - 0.995) /
(0.995 * 0.02222222) = 22.6131%


If you simply wanted to evaluate a zero rate (instead of the par rate) the
call would be, for example:
r2 = refTermStructure->zeroRate(QuantLib::Date(1, October, 2004),
termStructureDayCounterX, Simple, Annual, true);
wich also gives 22.6131%


Hope that helps

Best regards,

Giorgio


> -----Original Message-----
> From: Cliffy [mailto:[hidden email]]
> Sent: mercoledì, 18. novembre 2009 21:02
> To: [hidden email]
> Subject: Re: [Quantlib-users] YieldCurve from discount factors
>
>
> Hi, I am new to quantlib, read this post and out of curiosity want to
> try it
> out.
> I thought the usage of "InterpolatedDiscountCurve" is to provide a set
> of
> "discount factors" and
> be able to calculate par rates on the curve.
>
> I use a simple unrealistic discount curve (to 30 days) -
>
> Date Disc factor
>
> Sep 23   1
> Oct 1     0.995
> Nov 3     0.992
>
> try to calculate par rate as of Oct 1, I got
>
> 0.0050251256281407079
>
> it seemd to be too small, shouldn't be around 20%??
>
> here are the codes,
>
>     vector<Date> dates;
>     vector<DiscountFactor> rates;
>     vector<Date> datesIn;
>
>     DayCounter termStructureDayCounterX = Actual360();;
>     Calendar calendarX = TARGET();
>
>     Date settlementDateX(22, September, 2004);
>     Date d1 = calendarX.advance(settlementDateX, 1,Days);
>     dates.push_back(d1);
>     d1 = calendarX.advance(settlementDateX, 7,Days);
>     dates.push_back(d1);
>     d1 = calendarX.advance(settlementDateX, 30,Days);
>     dates.push_back(d1);
>     Rate r1 = 1;
>     rates.push_back(r1);
>     r1 = 0.995;
>     rates.push_back(r1);
>     r1 = 0.992;
>     rates.push_back(r1);
>
>     Handle<YieldTermStructure>
>     refTermStructure(boost::shared_ptr<YieldTermStructure>(
>        new InterpolatedDiscountCurve<LogLinear>(dates, rates,
>     termStructureDayCounterX)));
>
>     d1 = calendarX.advance(settlementDateX, 1,Days);
>     datesIn.push_back(d1);
>     d1 = calendarX.advance(settlementDateX, 7,Days);
>     datesIn.push_back(d1);
>
>     Rate r2;
>     r2 = refTermStructure->parRate(datesIn,Annual,true);
>
>     cout << r2;  // r2 = 0.0050251256281407079
>
> What did I do wrong here??
>
> Regards,
>
> Cliff
>
> --
> View this message in context: http://old.nabble.com/YieldCurve-from-
> discount-factors-tp26375800p26414696.html
> Sent from the quantlib-users mailing list archive at Nabble.com.
>
>
> -----------------------------------------------------------------------
> -------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve from discount factors (2)

Giorgio Pazmandi
Sorry, I did not see that QL uses the frequency passed in input for the
calculation of the parrate, i.e. the formula is correct and is

ParRate = (DF_start - DF_end) * frequency / \SUM(DF_i),

This is equivalent to my formula if (t_i - t_{i-1}) = 1/frequency (as it
should for a "normal" swap :-) )

Basically, you are evaluating a rate for a 1 year period that accrues the
same as the 8-day period:

R * t * DF = 0.50251256281407079% * 1 * 0.995 = 22.6131% * 0.022222222 *
0.995

Regards,

Giorgio Pazmandi



> -----Original Message-----
> From: Giorgio Pazmandi [mailto:[hidden email]]
> Sent: giovedì, 19. novembre 2009 10:58
> To: 'Cliffy'; [hidden email]
> Subject: Re: [Quantlib-users] YieldCurve from discount factors
>
> Hi Cliffy, the par rate is calculated in QL with the formula
> ParRate = (DF_start - DF_end) / \SUM(DF_i) = (1 - 0.995) / (0.995) =
> 0.0050251256281407079
>
> Maybe I'm wrong, but I would have expected:
> ParRate = (DF_start - DF_end) / \SUM(DF_i * (T_i - T_{i-1})) = (1 -
> 0.995) /
> (0.995 * 0.02222222) = 22.6131%
>
>
> If you simply wanted to evaluate a zero rate (instead of the par rate)
> the
> call would be, for example:
> r2 = refTermStructure->zeroRate(QuantLib::Date(1, October, 2004),
> termStructureDayCounterX, Simple, Annual, true);
> wich also gives 22.6131%
>
>
> Hope that helps
>
> Best regards,
>
> Giorgio
>
>
> > -----Original Message-----
> > From: Cliffy [mailto:[hidden email]]
> > Sent: mercoledì, 18. novembre 2009 21:02
> > To: [hidden email]
> > Subject: Re: [Quantlib-users] YieldCurve from discount factors
> >
> >
> > Hi, I am new to quantlib, read this post and out of curiosity want to
> > try it
> > out.
> > I thought the usage of "InterpolatedDiscountCurve" is to provide a
> set
> > of
> > "discount factors" and
> > be able to calculate par rates on the curve.
> >
> > I use a simple unrealistic discount curve (to 30 days) -
> >
> > Date Disc factor
> >
> > Sep 23   1
> > Oct 1     0.995
> > Nov 3     0.992
> >
> > try to calculate par rate as of Oct 1, I got
> >
> > 0.0050251256281407079
> >
> > it seemd to be too small, shouldn't be around 20%??
> >
> > here are the codes,
> >
> >     vector<Date> dates;
> >     vector<DiscountFactor> rates;
> >     vector<Date> datesIn;
> >
> >     DayCounter termStructureDayCounterX = Actual360();;
> >     Calendar calendarX = TARGET();
> >
> >     Date settlementDateX(22, September, 2004);
> >     Date d1 = calendarX.advance(settlementDateX, 1,Days);
> >     dates.push_back(d1);
> >     d1 = calendarX.advance(settlementDateX, 7,Days);
> >     dates.push_back(d1);
> >     d1 = calendarX.advance(settlementDateX, 30,Days);
> >     dates.push_back(d1);
> >     Rate r1 = 1;
> >     rates.push_back(r1);
> >     r1 = 0.995;
> >     rates.push_back(r1);
> >     r1 = 0.992;
> >     rates.push_back(r1);
> >
> >     Handle<YieldTermStructure>
> >     refTermStructure(boost::shared_ptr<YieldTermStructure>(
> >        new InterpolatedDiscountCurve<LogLinear>(dates, rates,
> >     termStructureDayCounterX)));
> >
> >     d1 = calendarX.advance(settlementDateX, 1,Days);
> >     datesIn.push_back(d1);
> >     d1 = calendarX.advance(settlementDateX, 7,Days);
> >     datesIn.push_back(d1);
> >
> >     Rate r2;
> >     r2 = refTermStructure->parRate(datesIn,Annual,true);
> >
> >     cout << r2;  // r2 = 0.0050251256281407079
> >
> > What did I do wrong here??
> >
> > Regards,
> >
> > Cliff
> >
> > --
> > View this message in context: http://old.nabble.com/YieldCurve-from-
> > discount-factors-tp26375800p26414696.html
> > Sent from the quantlib-users mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> --
> > -------
> > Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> > 30-Day
> > trial. Simplify your report design, integration and deployment - and
> > focus on
> > what you do best, core application coding. Discover what's new with
> > Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> > _______________________________________________
> > QuantLib-users mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
>
> -----------------------------------------------------------------------
> -------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users