Login  Register

Re: Adjustable Rate Bonds Pricing

Posted by d0tc0mguy on Jun 16, 2011; 5:31am
URL: http://quantlib.414.s1.nabble.com/Adjustable-Rate-Bonds-Pricing-tp5756p5759.html

If I just set the fixingdates as -1  would it work the same way.


d0tc0mguy wrote
I am passing the two fixings dates as a timeseries through addfixings()

#include <ql/quantlib.hpp>
#include <boost/foreach.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
#include <ql/utilities/dataformatters.hpp>
//#include "utilities.hpp"

using namespace QuantLib;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }

}
#endif

    struct Datum {
        Integer n;
        TimeUnit units;
        Rate rate;
    };


int main(int, char* []) {

    try {

        boost::timer timer;
        std::cout << std::endl;

 
        Calendar calendar = TARGET();

        Date settlementDate(21, October, 2008);
 
        Integer fixingDays = 0;
        Natural settlementDays = 0;

        Date todaysDate = calendar.advance(settlementDate, -fixingDays, Days);
        Settings::instance().evaluationDate() = todaysDate;

                Currency USD = USDCurrency();

        std::cout << "Today: " << todaysDate.weekday()
        << ", " << todaysDate << std::endl;

        std::cout << "Settlement date: " << settlementDate.weekday()
        << ", " << settlementDate << std::endl;
                        DayCounter termStructureDayCounter =
             ActualActual(ActualActual::ISDA);

         double tolerance = 1.0e-15;;
                         
        std::vector<Date> dates;
    std::vector<Rate> rates;
    dates.push_back(settlementDate);
    dates.push_back(calendar.advance(settlementDate, 1, Years));
        dates.push_back(calendar.advance(settlementDate, 2, Years));
        dates.push_back(calendar.advance(settlementDate, 3, Years));
        dates.push_back(calendar.advance(settlementDate, 4, Years));
    rates.push_back(0.01);
    rates.push_back(0.015);
        rates.push_back(0.02);
        rates.push_back(0.025);
        rates.push_back(0.03);
       
        boost::shared_ptr<YieldTermStructure> bondDiscountingTermStructure(
                                    new InterpolatedZeroCurve<Linear>(dates, rates,termStructureDayCounter));
         
       
                            Datum depositData[] = {
                { 1, Months, 6.000 },
                { 2, Months, 6.100 },
                { 3, Months, 6.200 },
                { 6, Months, 6.300 },
                { 9, Months, 6.400 }
            };
            Datum swapData[] = {
                {  1, Years, 6.500 },
                {  5, Years, 7.000 }//,
              //  { 10, Years, 7.500 },
               // { 20, Years, 8.000 },
               // { 30, Years, 9.000 }
            };
            Size deposits = 5,
                swaps = 2;

            std::vector<boost::shared_ptr<RateHelper> > instruments(
                                                              deposits+swaps);
            for (Size i=0; i<deposits; i++) {
                instruments[i] = boost::shared_ptr<RateHelper>(new
                    DepositRateHelper(depositData[i].rate/100,
                                      depositData[i].n*depositData[i].units,
                                      settlementDays, calendar,
                                      ModifiedFollowing, true,
                                      ActualActual()));
            }
                                    boost::shared_ptr<IborIndex> index(new IborIndex("dummy",
                                                             3*Months,
                                                             settlementDays,
                                                             USD,
                                                             calendar,
                                                             ModifiedFollowing,
                                                             false,
                                                             ActualActual()));
            for (Size i=0; i<swaps; ++i) {
                instruments[i+deposits] = boost::shared_ptr<RateHelper>(new
                    SwapRateHelper(swapData[i].rate/100,
                                   swapData[i].n*swapData[i].units,
                                   calendar,
                                   Annual, Unadjusted, ActualActual(),
                                   index));
            }
            boost::shared_ptr<YieldTermStructure> termStructure(new
                PiecewiseYieldCurve<Discount,Linear>(settlementDate,
                                                        instruments,
                                                                                                                termStructureDayCounter,
                                                                                                                tolerance));

                RelinkableHandle<YieldTermStructure> discountingTermStructure;
         
         RelinkableHandle<YieldTermStructure> forecastingTermStructure;

         Real faceAmount = 100;

         boost::shared_ptr<PricingEngine> bondEngine(
                 new DiscountingBondEngine(discountingTermStructure));

         
         RelinkableHandle<YieldTermStructure> liborTermStructure;
               
                 const boost::shared_ptr<IborIndex> libor3m(
                 new USDLibor(Period(3,Months),liborTermStructure));
         //libor3m->addFixing(Date(19, October, 2009),0.0378625);
                 

                 
         Schedule floatingBondSchedule(Date(21, October, 2008),
                 Date(21, October, 2010), Period(Annual),
                 UnitedStates(UnitedStates::NYSE),
                 Unadjusted, Unadjusted, DateGeneration::Forward, true);

                  FloatingRateBond floatingRateBond(
                 settlementDays,
                 faceAmount,
                 floatingBondSchedule,
                 libor3m,
                 ActualActual(),
                 ModifiedFollowing,
                 Natural(0),
                 // Gearings
                 std::vector<Real>(1, 1.0),
                                // std::vector<Real>(),
                 // Spreads
                std::vector<Rate>(1, 0.000),
                                 //std::vector<Rate>(),
                 // Caps
                 std::vector<Rate>(),
                 // Floors
                 std::vector<Rate>(),
                 // Fixing in arrears
                 true,
                 Real(100.0),
                 Date(21, October, 2008));

         floatingRateBond.setPricingEngine(bondEngine);

         boost::shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer);

         Volatility volatility = 0.0;
         Handle<OptionletVolatilityStructure> vol;
         vol = Handle<OptionletVolatilityStructure>(
                 boost::shared_ptr<OptionletVolatilityStructure>(new
                         ConstantOptionletVolatility(
                                 settlementDays,
                                 calendar,
                                 ModifiedFollowing,
                                 volatility,
                                 ActualActual())));

         pricer->setCapletVolatility(vol);
         setCouponPricer(floatingRateBond.cashflows(),pricer);

                 forecastingTermStructure.linkTo(termStructure);
         discountingTermStructure.linkTo(bondDiscountingTermStructure);
         liborTermStructure.linkTo(termStructure);

                 TimeSeries<Real> Fixings;
                 //ERROR --> FUNCTION IS inaccessible
                 //Fixings[Date(20,October,2009)] = libor3m->forecastFixing(Date(20,October,2009));
                 //Fixings[Date(20,October,2010)] = libor3m->forecastFixing(Date(20,October,2010));
                Fixings[Date(20,October,2009)] = liborTermStructure->zeroRate(liborTermStructure->timeFromReference(Date(20,October,2009)),Compounded,Annual,false) ;
                Fixings[Date(20,October,2010)] = liborTermStructure->zeroRate(liborTermStructure->timeFromReference(Date(20,October,2010)),Compounded,Annual,false) ;
                 
                 libor3m->addFixings(Fixings,true);
               
         std::cout << std::endl;
                 /*
                 std :: cout << "Floating Bond - Cashflows :" << std::endl;
                const std::vector<boost::shared_ptr<QuantLib::CashFlow> >& ftleg = floatingRateBond.cashflows();
                for (int j = 0; j<ftleg.size(); j++){
                        std :: cout << "Date :" << ftleg[j]->date()
                                << "  FloatingLeg CashFlow :" << std::fixed <<
                                std::setprecision(5) << (ftleg[j]->amount()) << std :: endl ;
                }*/
                 std::cout<< floatingRateBond.NPV();
               

       return 0;

    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    } catch (...) {
        std::cerr << "unknown error" << std::endl;
        return 1;
    }
}


Luigi Ballabio wrote
On Wed, 2011-06-15 at 04:56 -0700, d0tc0mguy wrote:
> Hi,
>
> I am trying to use the Quantlib Library to price a adjustable rate bond. It
> is a Annual Coupon Bond. The bond coupon rate is repriced every 6 months. I
> am using the FloatingRateBond class for the pricing.
>
> I'm not able to understand
> 1) how to pass the repricing frequency as 6 months to be yield curve?
> 2) Im using the indexfixing. Is this right?

Can you show your code so far?

Luigi


--

When all else fails, pour a pint of Guinness in the gas tank,
advance the spark 20 degrees, cry "God Save the Queen!", and pull
the starter knob.
-- MG "Series MGA" Workshop Manual



------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
QuantLib-users mailing list
QuantLib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users