Bootstrapping US Treasury Curve with fake zero coupon bonds

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

Bootstrapping US Treasury Curve with fake zero coupon bonds

Irakli Machabeli-2

Hi,

I'm trying to bootstrap treasury curve with cubic spline including t-bill( short dated with no coupon)
Since quantlib doesn't support zeros I add fixed rate bond helper with real price and very small coupon.
During bootstrap I get an error

1st iteration: could not bootstrap the 1st instrument, maturity February 19th, 2009:
root not bracketed: f[2.22045e-016,3] -> [-9.989025e+001,-4.726847e+001]

>From the point of view of yield calculation price 99.89 and coupon 0.00001    makes sense.
Can anyone suggest whet I'm doing wrong or it's a bug and discount bonds(price less than 100)  are not handled properly?



Below are the bonds used to fitting:
CUSIP     HASCPN FREQ        CPN       ISSUEDATE    MATDATE       BBGNAME        VALUEDATE    PRICE
912795K42    N    0           0        8/21/2008    2/19/2009     CB3 Govt      11/18/2008    0.11
912795L90    N    0           0        11/20/2008   5/21/2009     CB6 Govt      11/18/2008    0.74
912795S44    N    0           0        10/23/2008   10/22/2009    CB12 Govt     11/18/2008    0.99
912810PX0    Y    2           4.5      8/15/2008    5/15/2038     CT30 Govt     11/18/2008    106.9844
912828JP6    Y    2           1.5      10/31/2008   10/31/2010    CT02 Govt     11/18/2008    100.75
912828JQ4    Y    2           2.75     10/31/2008   10/31/2013    CT05 Govt     11/18/2008    102.8438
912828JR2    Y    2           3.75     11/17/2008   11/15/2018    CT10 Govt     11/18/2008    102.2656

For zeros I'm passing 100-price as input to quantlib and coupon  0.00001, Frequency.Annual, BusinessDayConvention.Following

Irakli

_________________________________________________________________
Get more done, have more fun, and stay more connected with Windows MobileĀ®.
http://clk.atdmt.com/MRT/go/119642556/direct/01/
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bootstrapping US Treasury Curve with fake zero coupon bonds

Luigi Ballabio
On Wed, 2008-11-19 at 09:38 -0500, Irakli Machabeli wrote:
> I'm trying to bootstrap treasury curve with cubic spline including t-bill( short dated with no coupon)
> Since quantlib doesn't support zeros I add fixed rate bond helper with real price and very small coupon.
> During bootstrap I get an error

Apologies for the delay---can you post the code that triggers the
problem?

Luigi


--

There's no sense in being precise when you don't even know what you're
talking about.
-- John von Neumann



------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bootstrapping US Treasury Curve with fake zero coupon bonds

Irakli Machabeli-2
Luigi,

I get this error if I try to bootstrap curve from c# code
1st iteration: could not bootstrap the 1st instrument, maturity March 19th,
2009: root not bracketed: f[2.22045e-016,3] ->
[-9.996249e+001,-4.730857e+001]


I made sample using C++ too. Now in C++ sample I'm actually getting memory
corruption error in some cases.

If you exclude 1st 3 bonds in source code all tests pass smoothly (it works
also from c# side).
With those 3 bonds included you get an error

One year zero=0.558764 % Actual/Actual (ISDA) simple compounding
done fitCurve<Discount,LogLinear,IterativeBootstrap>

failed fitCurve<ForwardRate,Cubic,IterativeBootstrap>
1st iteration: could not bootstrap the 3rd instrument, maturity November
19th, 2
009: root not bracketed: f[2.22045e-016,3] -> [4.166294e-001,3.803735e+001]

One year zero=0.525826 % Actual/Actual (ISDA) simple compounding
done fitCurve<ZeroYield,Cubic,IterativeBootstrap>

One year zero=0.547035 % Actual/Actual (ISDA) simple compounding
done fitCurve<ForwardRate,ConvexMonotone,IterativeBootstrap>


If you do not catch exception in code debugger shows that there is memory
corruption : Unhandled exception at 0x004b8ee0 in
mytestsValuation-vc80-mt-sgd.exe: 0xC0000005: Access violation reading
location 0xfeeefef2.
so I guess "root not bracketed" is not a real issue

By the way is you change frequency for 1st 3 bonds from Annual to Monthly
( which should nor really matter since coupon is really small  one more test
fails)

Anyway attached is the sample :


#include <iostream>
#include <ql/quantlib.hpp>


using namespace std;
using namespace QuantLib;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

    Integer sessionId() { return 0; }

}
#endif

#define LENGTH(a) (sizeof(a)/sizeof(a[0]))

    struct BondData {
                Date issueDate;
        Date redemptionDate;
        Frequency frequency;
        Rate coupon;
        Real price;
    };

    BondData bondData[] = {
                {Date(18,(Month)9,2008),Date(19,(Month)3,2009), Annual,0.01,99.9600},
                {Date(18,(Month)12,2008),Date(18,(Month)6,2009), Annual,0.01,99.7350},
                {Date(20,(Month)11,2008),Date(19,(Month)11,2009), Annual,0.01,99.5300},
                {Date(1,(Month)12,2008),Date(30,(Month)11,2010),
Semiannual,1.25,100.9531},
                {Date(1,(Month)12,2008),Date(30,(Month)11,2013), Semiannual,2,102.3281},
                {Date(17,(Month)11,2008),Date(15,(Month)11,2018),
Semiannual,3.75,110.7813},
                {Date(15,(Month)8,2008),Date(15,(Month)5,2038), Semiannual,4.5,130.5000}
    };

        Date today=Date(16,(Month)12,2008);//calendar.adjust(Date::todaysDate());




    template <class T, class I, template<class C> class B>
    void fitCurve(const I& interpolator = I(),
                              Real tolerance = 1.0e-9)
        {


                Size bondCount = LENGTH(bondData);

        Calendar calendar=  JointCalendar(
                        UnitedStates(UnitedStates::Market::GovernmentBond ),
                        UnitedKingdom(UnitedKingdom::Market::Settlement ),
                        JointCalendarRule::JoinHolidays );

        //Natural settlementDays;
                std::vector<boost::shared_ptr<SimpleQuote> >prices(bondCount);
                std::vector<Schedule> schedules(bondCount);

        Settings::instance().evaluationDate() = today;
                Natural bondSettlementDays=2;
                Date settlementDay= calendar.advance(today,bondSettlementDays,Days);

        DayCounter bondDayCounter= ActualActual();
        BusinessDayConvention bondConvention= Following;
        Real bondRedemption=100;

            std::vector<boost::shared_ptr<RateHelper> >
bondHelpers(bondCount );

            for (Size i=0; i<bondCount ; i++)
                        {
                                prices[i]= boost::shared_ptr<SimpleQuote>( new
SimpleQuote(bondData[i].price) );

                std::vector<Rate> coupons(1, bondData[i].coupon/100.0);

                schedules[i] =  Schedule( bondData[i].issueDate,
                                                                                bondData[i].redemptionDate ,
                                        Period(bondData[i].frequency),
                                        calendar,
                                        bondConvention, bondConvention,
                                        DateGeneration::Backward, false);

                                Handle<Quote> p(prices[i]);

                bondHelpers[i] = boost::shared_ptr<RateHelper>(new
                    FixedRateBondHelper(p,
                                        bondSettlementDays,
                                        bondRedemption, schedules[i],
                                        coupons, bondDayCounter,
                                        bondConvention,
                                        bondRedemption,
bondData[i].issueDate));


                        }



        boost::shared_ptr<YieldTermStructure> yc(
              new PiecewiseYieldCurve<T,I,B>(bondSettlementDays,
                                                          calendar,
                                                          bondHelpers,
                                                          bondDayCounter));


                InterestRate r= yc->zeroRate(1, Compounding::Simple  );
                Date maxD= yc->maxDate();
                cout<< "One year zero="<<r<<endl;//  <<" maxDate= "<<maxD <<endl;


        }


        int main(int, char* [])
        {

                //fitCurve<ForwardRate,Cubic,IterativeBootstrap>();

                try
                {
                        fitCurve<Discount,LogLinear,IterativeBootstrap>();
                        cout<<"done fitCurve<Discount,LogLinear,IterativeBootstrap>";
                }
                catch( QuantLib::Error& e )
                {
                        cout<<"failed
fitCurve<Discount,LogLinear,IterativeBootstrap>"<<endl<<e.what();

                }
                cout<<endl<<endl;


                try
                {
                        fitCurve<ForwardRate,Cubic,IterativeBootstrap>();
                        cout<<"done fitCurve<ForwardRate,Cubic,IterativeBootstrap>";
                }
                catch( QuantLib::Error& e )
                {
                        cout<<"failed
fitCurve<ForwardRate,Cubic,IterativeBootstrap>"<<endl<<e.what();
                }
                cout<<endl<<endl;

                try
                {
                        fitCurve<ZeroYield,Cubic,IterativeBootstrap>();
                        cout<<"done fitCurve<ZeroYield,Cubic,IterativeBootstrap>";
                }
                catch( QuantLib::Error& e )
                {
                        cout<<"failed
fitCurve<ZeroYield,Cubic,IterativeBootstrap>"<<endl<<e.what();
                }
                cout<<endl<<endl;

                try
                {
                        fitCurve<ForwardRate,ConvexMonotone,IterativeBootstrap>();
                        cout<<"done
fitCurve<ForwardRate,ConvexMonotone,IterativeBootstrap>"<<endl<<endl;
                }
                catch( QuantLib::Error& e )
                {
                        cout<<"failed
fitCurve<ForwardRate,ConvexMonotone,IterativeBootstrap>"<<endl<<e.what();
                }
                cout<<endl<<endl;






                char c;
                cin>>c;
        }








--------------------------------------------------
From: "Luigi Ballabio" <[hidden email]>
Sent: Wednesday, December 17, 2008 10:15 AM
To: "Irakli Machabeli" <[hidden email]>
Cc: <[hidden email]>
Subject: Re: [Quantlib-users] Bootstrapping US Treasury Curve with fake zero
coupon bonds

> On Wed, 2008-11-19 at 09:38 -0500, Irakli Machabeli wrote:
>> I'm trying to bootstrap treasury curve with cubic spline including
>> t-bill( short dated with no coupon)
>> Since quantlib doesn't support zeros I add fixed rate bond helper with
>> real price and very small coupon.
>> During bootstrap I get an error
>
> Apologies for the delay---can you post the code that triggers the
> problem?
>
> Luigi
>
>
> --
>
> There's no sense in being precise when you don't even know what you're
> talking about.
> -- John von Neumann
>
>
>

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bootstrapping US Treasury Curve with fake zero coupon bonds

pdrubetskoy
Hi,
I am also having similar issues bootstrapping a treasury curve with QuantLib. Has there been any resolution to this thread?
Any help would be appreciated,
Peter


Irakli Machabeli-2 wrote
Luigi,

I get this error if I try to bootstrap curve from c# code
1st iteration: could not bootstrap the 1st instrument, maturity March 19th,
2009: root not bracketed: f[2.22045e-016,3] ->
[-9.996249e+001,-4.730857e+001]

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

Re: Bootstrapping US Treasury Curve with fake zero coupon bonds

Luigi Ballabio
On Tue, 2009-10-20 at 11:51 -0700, pdrubetskoy wrote:
> I am also having similar issues bootstrapping a treasury curve with
> QuantLib. Has there been any resolution to this thread?

Not that I know of.  However, my guess is that unconstrained Cubic
interpolation oscillates too much and the bootstrapper cannot find a
solution; other interpolations work.

Would you have time to debug the problem?

Luigi


--

I'd never join any club that would have the likes of me as a member.
-- Groucho Marx



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bootstrapping US Treasury Curve with fake zero coupon bonds

pdrubetskoy
Thanks, Luigi.
This particular problem was actually caused by me passing 0 for bond redemptions by mistake, sorry!


Luigi Ballabio wrote
On Tue, 2009-10-20 at 11:51 -0700, pdrubetskoy wrote:
> I am also having similar issues bootstrapping a treasury curve with
> QuantLib. Has there been any resolution to this thread?

Not that I know of.  However, my guess is that unconstrained Cubic
interpolation oscillates too much and the bootstrapper cannot find a
solution; other interpolations work.

Would you have time to debug the problem?

Luigi


--

I'd never join any club that would have the likes of me as a member.
-- Groucho Marx



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
QuantLib-users mailing list
QuantLib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users