Bonds Helper class...

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

Bonds Helper class...

Toyin Akin
Hi guys,

What do you guys think of this first implementation of a Bonds Helper class
in order to strip a bonds curve.
(Deposits+Futures+Bonds)

I'm not too sure whether both the issueDate and datedDate are needed.

What exactly is the dated date?

Header file :

#############################################################################################

#ifndef quantlib_bondhelper_hpp
#define quantlib_bondhelper_hpp

#include <ql/Instruments/FixedCouponBond.hpp>
#include <ql/TermStructures/ratehelpers.hpp>

namespace QuantLib
{
    class BondHelper : public RateHelper
        {
      public:

        BondHelper(const Handle<Quote>& Price,
                const Date& issueDate,
                        const Date& datedDate,
                        const Date& maturityDate,
                        Integer settlementDays,
                        const std::vector<Rate>& coupons,
                        Frequency couponFrequency,
                        const DayCounter& dayCounter,
                        const Calendar& calendar,
                        BusinessDayConvention convention = Following,
                        Real redemption = 100.0,
                        const Date& stub = Date(),
                        bool fromEnd = true);

        Real impliedQuote() const;
        // implementing discountGuess() is not worthwhile,
        // and may not avoid the root-finding process
        Date latestDate() const;
        void setTermStructure(YieldTermStructure*);

      protected:

        Integer settlementDays_;
        Calendar calendar_;
        BusinessDayConvention businessDayConvention_;
        DayCounter dayCount_;

        Date stub_;
        bool fromEnd_;
        std::vector<Rate> coupons_;

        Date issueDate_, datedDate_, maturityDate_;
        Frequency frequency_;
        Real redemption_;
        Date settlement_, latestDate_;

        boost::shared_ptr<FixedCouponBond> bond_;
        Handle<YieldTermStructure> termStructureHandle_;
    };
}


#endif

#############################################################################################


cpp file :

#############################################################################################

#include <ql/TermStructures/BondHelper.hpp>

namespace QuantLib
{

    namespace
        {
        void no_deletion(YieldTermStructure*) {}
    }

    BondHelper::BondHelper(const Handle<Quote>& Price,
                             const Date& issueDate,
                             const Date& datedDate,
                             const Date& maturityDate,
                             Integer settlementDays,
                             const std::vector<Rate>& coupons,
                             Frequency couponFrequency,
                             const DayCounter& dayCounter,
                             const Calendar& calendar,
                             BusinessDayConvention convention,
                             Real redemption,
                             const Date& stub, bool fromEnd)
        : RateHelper(Price)
        {

                coupons_ = coupons;
                settlementDays_ = settlementDays;
                businessDayConvention_ = convention;
                calendar_ = calendar;
                dayCount_ = dayCounter;

                stub_ = stub;
                fromEnd_ = fromEnd;

                issueDate_ = issueDate;
        datedDate_ = datedDate;
                maturityDate_ = maturityDate;
        frequency_ = couponFrequency;
                redemption_ = redemption;

                registerWith(Settings::instance().evaluationDate());

    }



    void BondHelper::setTermStructure(YieldTermStructure* t)
        {
        // do not set the relinkable handle as an observer -
        // force recalculation when needed
        termStructureHandle_.linkTo(
                         
boost::shared_ptr<YieldTermStructure>(t,no_deletion),
                         false);

        RateHelper::setTermStructure(t);
        Date today = Settings::instance().evaluationDate();
        settlement_ = calendar_.advance(today,settlementDays_,Days);

        bond_ = boost::shared_ptr<FixedCouponBond>(
                   new FixedCouponBond(issueDate_, datedDate_,
maturityDate_,
                                  settlementDays_, coupons_,
                                  frequency_, dayCount_, calendar_,
businessDayConvention_,
                                  redemption_, termStructureHandle_,
                                                                  stub_, fromEnd_));

        latestDate_ = maturityDate_;
    }

    Date BondHelper::latestDate() const
        {
        QL_REQUIRE(termStructure_ != 0, "null term structure set");
        return latestDate_;
    }

    Real BondHelper::impliedQuote() const
        {
        QL_REQUIRE(termStructure_ != 0, "term structure not set");
        // we didn't register as observers - force calculation
        bond_->recalculate();
        return bond_->NPV();
    }
}


#############################################################################################

If you find it useful, can you merge this into the Quantlib source?

Best Regards,
Toy out.




Reply | Threaded
Open this post in threaded view
|

Re: Bonds Helper class...

Luigi Ballabio
On 08/02/2005 05:24:02 PM, Toyin Akin wrote:
>
> What do you guys think of this first implementation of a Bonds Helper  
> class in order to strip a bonds curve.
> (Deposits+Futures+Bonds)

The implementation seems ok to me. But I'm not sure that it should be  
used together with deposits and futures, as bond quotes include the  
credit spread of the bond issuer while deposit and futures quotes  
don't. I think it would be better to bootstrap a curve on bonds  
alone---possibly choosing bonds with the same issuer, or at least  
similar ones with respect to rating.

> If you find it useful, can you merge this into the Quantlib source?

I will, as soon as I get a bit of time.

Thanks,
        Luigi


----------------------------------------

Call on God, but row away from the rocks.
-- Indian proverb



Reply | Threaded
Open this post in threaded view
|

Re: Bonds Helper class...

Toyin Akin
Thanks Luigi,

Toy out.


>From: Luigi Ballabio <[hidden email]>
>To: Toyin Akin <[hidden email]>
>CC: [hidden email]
>Subject: Re: [Quantlib-users] Bonds Helper class...
>Date: Wed, 24 Aug 2005 15:51:55 +0000
>
>
>On 08/02/2005 05:24:02 PM, Toyin Akin wrote:
>>
>>What do you guys think of this first implementation of a Bonds Helper  
>>class in order to strip a bonds curve.
>>(Deposits+Futures+Bonds)
>
>The implementation seems ok to me. But I'm not sure that it should be  used
>together with deposits and futures, as bond quotes include the  credit
>spread of the bond issuer while deposit and futures quotes  don't. I think
>it would be better to bootstrap a curve on bonds  alone---possibly choosing
>bonds with the same issuer, or at least  similar ones with respect to
>rating.
>
>>If you find it useful, can you merge this into the Quantlib source?
>
>I will, as soon as I get a bit of time.
>
>Thanks,
> Luigi
>
>
>----------------------------------------
>
>Call on God, but row away from the rocks.
>-- Indian proverb
>
>
>
>-------------------------------------------------------
>SF.Net email is Sponsored by the Better Software Conference & EXPO
>September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
>Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
>Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
>_______________________________________________
>Quantlib-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/quantlib-users