Quantlib Floating rate bond with known first cash flow and forecasted cash flows equal

1.7k views Asked by At

I am trying to price a floating rate bond and I already have the discount curve built with quantlib on C++. Now what I would like to do is to use the FloatingRateBond class and create a set of cash flows where the first cash flow is known (given that the index associated to this cash flow was known at the last reset date) and forecasting the remaining cash flows using the current index.

To make it more graphical assume annual payments and that the index at the last reset date was 1% and that the reset margin is 1%. Then the first cash flow will be 2% roughly speaking. Now assume that today's index is 2%, then I want all the remaining cash flows to be 3% (with the proper adjustments from the Day Count convention and Business Day convention).

How can I create such a cash flow structure for an instance of the FloatingRateBond class?

1

There are 1 answers

3
Luigi Ballabio On

First I'll go quickly through building the bond, copying some code from the bonds example in the QuantLib release (also, disclaimer: I haven't tried compiling the code below). For more details on the classes involved, see the QuantLib documentation.

Let's assume annual payments as you said:

Schedule schedule(startDate, maturityDate, Period(Annual),
                  calendar, convention, convention,
                  DateGeneration::Backward, true);

and for illustration, let's assume we'll use an USD Libor index. Its future fixing are forecast based on an interest-rate term structure we'll set later.

RelinkableHandle<YieldTermStructure> liborTermStructure;
boost::shared_ptr<IborIndex> libor(
             new USDLibor(Period(1,Years),liborTermStructure));

Now build the bond, adding the margin as a spread on the LIBOR rate:

FloatingRateBond bond(settlementDays, faceAmount,
                      schedule, libor, dayCounter,
                      convention, fixingDays,
                      // gearings
                      std::vector<Real>(1, 1.0),
                      // spreads
                      std::vector<Rate>(1, 0.001));

Now to get the coupons you want, you'll just set the corresponding market data. To set the rate of the first cash flow, store the past fixing of the Libor index:

libor->addFixing(resetDate, 0.01);

And to set the future cash flows, create a flat interest-rate curve with the desired rate (minding the conventions so that they match those of the Libor index):

boost::shared_ptr<YieldTermStructure> flatRate(
    new FlatForward(today, 0.01, dayCounter, Simple, Annual));
liborTermStructure.linkTo(flatRate);

(You're not necessarily limited to a flat rate; if you can bootstrap a Libor curve, you can use that one to get realistic estimates for future coupons.)

At this point, you should be able to extract the bond coupons and check that they're as expected:

std::vector<boost::shared_ptr<CashFlow> > cashflows = bond.cashflows();
for (std::size_t i=0; i < cashflows.size(); ++i)
    std::cout << cashflows[i]->date() << "    "
              << cashflows[i]->amount() << "\n";

If you also want to call methods such as bond.cleanPrice(), you'll need to tell the bond how to discount the cash flows:

RelinkableHandle<YieldTermStructure> discountingTermStructure;
boost::shared_ptr<PricingEngine> bondEngine(
             new DiscountingBondEngine(discountingTermStructure));
bond.setPricingEngine(bondEngine);

You can use for discounting the same curve you're using for forecasting...

discountingTermStructure.linkTo(flatRate);

...or create and use a different one.