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?
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 aboost::shared_ptr<YieldTermStructure>, and so isbondDiscountingTermStructure. They basically behave as pointers toYieldTermStructure.Then, you have instances of
Handle<YieldTermStructure>(orRelinkableHandle) which give you another level of indirection: aHandlecontains ashared_ptrand 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
libor3mindex is passed theliborTermStructurehandle, so it will forecast its fixings by using whatever curve is linked to it: in this case,depoSwapTermStructure, since the statementis 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
liborTermStructureto 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
discountingTermStructurewill be used to discount the cash flows; in the example, that would bebondDiscountingTermStructure.As for how the coupon rates are calculated: each coupon calculates its own rate and amount with the help of the
BlackIborCouponPricerinstance that is built right after the bond and associated to the coupons shortly afterwards by the statementThe code that actually performs the calculation involves the
BlackIborCouponPricerandFloatingRateCouponclasses (more details are here and in the posts that follow) but ultimately the rate is calculated in theIborIndexclass as: