Quantlib FloatingRateBond cashflow computation

847 views Asked by At

Looking at the Bond.cpp example: http://quantlib.org/reference/_bonds_8cpp-example.html it looks like depoSwapTermStructure and liborTermStructure are exactly the same curve. However, for the floating rate bond it seems that the FloatingRateBond class is computing the coupon rates, and therefore the cashflows, for the floatingRateBond instance by computing the forward rates and then adding the spread to it (which sounds right to me).

Is this correct or is it the case for this example that the forecasted cashflows are being computed by taking the spot curve only and adding the spread to obtain the forecasted coupon rates?

1

There are 1 answers

2
Luigi Ballabio On

There are two different kind of objects at play in the example.

Actual curves are built and stored inside smart pointers; for instance, depoSwapTermStructure (the spot curve) is a boost::shared_ptr<YieldTermStructure>, and so is bondDiscountingTermStructure. They basically behave as pointers to YieldTermStructure.

Then, you have instances of Handle<YieldTermStructure> (or RelinkableHandle) which give you another level of indirection: a Handle contains a shared_ptr and can switch it for another if needed (the rationale for that and a few more details are available at this link).

In the example, the libor3m index is passed the liborTermStructure handle, so it will forecast its fixings by using whatever curve is linked to it: in this case, depoSwapTermStructure, since the statement

liborTermStructure.linkTo(depoSwapTermStructure);

is executed before pricing the bond. As you say, the coupon rates are calculated by forecasting the index fixings off the curve and adding the spread. If we linked liborTermStructure to another curve and asked the bond for its cash flows again, they would be recalculated based on the new curve.

The same happens for discounting. Whatever curve is linked to discountingTermStructure will be used to discount the cash flows; in the example, that would be bondDiscountingTermStructure.

As for how the coupon rates are calculated: each coupon calculates its own rate and amount with the help of the BlackIborCouponPricer instance that is built right after the bond and associated to the coupons shortly afterwards by the statement

setCouponPricer(floatingRateBond.cashflows(),pricer);

The code that actually performs the calculation involves the BlackIborCouponPricer and FloatingRateCoupon classes (more details are here and in the posts that follow) but ultimately the rate is calculated in the IborIndex class as:

Rate IborIndex::forecastFixing(const Date& fixingDate) const {
    Date d1 = valueDate(fixingDate);
    Date d2 = maturityDate(d1);
    Time t = dayCounter_.yearFraction(d1, d2);
    return forecastFixing(d1, d2, t);
}

Rate IborIndex::forecastFixing(const Date& d1,
                                      const Date& d2,
                                      Time t) const {
    DiscountFactor disc1 = termStructure_->discount(d1);
    DiscountFactor disc2 = termStructure_->discount(d2);
    return (disc1/disc2 - 1.0) / t;
}