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?
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:
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.
Now build the bond, adding the margin as a spread on the LIBOR rate:
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:
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):
(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:
If you also want to call methods such as
bond.cleanPrice()
, you'll need to tell the bond how to discount the cash flows:You can use for discounting the same curve you're using for forecasting...
...or create and use a different one.