Skip to content
All library documents

Building QuantLib Bonds with Coupon Cash Flows

Article Quant Q&A · Author: user38862

Summary

The document describes a QuantLib-Python construction error caused by passing simple cash flows to a Bond constructor that expects a leg of coupons. The proposed correction is to represent scheduled interest payments as fixed-rate coupons, with payment dates, accrual periods, notional, coupon rate, and a day-count convention. For the example, the final coupon-bearing period also reflects a reduced notional, so its interest differs from earlier payments.

A second approach uses an amortizing fixed-rate bond with a schedule and a sequence of notionals, which is presented as a simpler way to obtain the intended cash flows. The example lists interest and principal payments to illustrate equivalence between the approaches. This is a specific API troubleshooting example rather than a general bond-pricing treatment; it does not explain valuation, conventions beyond those shown, or behavior across different QuantLib versions.

Key ideas

  • The Bond constructor example expects coupons rather than a leg made of simple cash flows.
  • Fixed-rate coupons specify payment timing, accrual periods, notional, rate, and day-count convention.
  • Changing the notional over time represents an amortizing bond structure.
  • An amortizing fixed-rate bond class can construct the schedule and cash flows more directly.
  • The example illustrates construction only and does not cover bond valuation.

Tags

Full text
# Error in QuantLib-Python when I use function "Bond"


# Error in QuantLib-Python when I use function "Bond"












I am using the "Bond" function in QuantLib-Python 1.14.

I am planning to use it in this way:

```
BondPtr::BondPtr(Natural,Calendar const &,Date const &,Leg const &)
```

I tried to construct the last parameter as `ql.Leg((cf1,cf2,cf3,cf4))`

where `cf1=ql.SimpleCashFlow(3,ql.Date(25,1,20XX))`, `cf2=...`, `cf3=...`, `cf4=...`

Finally, I got the error:

```
RuntimeError: no coupons provided
```

Can someone one tell me how to make it correct? Thank you a lot!

Here is my code for reference:

`import QuantLib as ql cf1=ql.SimpleCashFlow(3,ql.Date(25,1,2019)) cf2=ql.SimpleCashFlow(3,ql.Date(25,1,2020)) cf3=ql.SimpleCashFlow(53,ql.Date(25,1,2021)) cf4=ql.SimpleCashFlow(51.5,ql.Date(25,1,2022)) couponsLeg=ql.Leg() couponsLeg.push_back(cf1) couponsLeg.push_back(cf2) couponsLeg.push_back(cf3) couponsLeg.push_back(cf4) newBond=ql.Bond(0,ql.UnitedStates(),ql.Date(25,1,2018),couponsLeg)`

## Answer by David Duarte (score 1)

https://quant.stackexchange.com/a/50902

The problem is that the `Bond` constructor expects a leg of coupons and you are giving it a leg of simple cashflows.

You can build it like this (the redemptions will be assumed from the coupons):

```
dc = ql.Thirty360()
cf1 = ql.FixedRateCoupon(ql.Date(25,1,2019), 100, 0.03, dc, ql.Date(25,1,2018), ql.Date(25,1,2019))
cf2 = ql.FixedRateCoupon(ql.Date(25,1,2020), 100, 0.03, dc, ql.Date(25,1,2019), ql.Date(25,1,2020))
cf3 = ql.FixedRateCoupon(ql.Date(25,1,2021), 100, 0.03, dc, ql.Date(25,1,2020), ql.Date(25,1,2021))
cf4 = ql.FixedRateCoupon(ql.Date(25,1,2022), 50, 0.03, dc, ql.Date(25,1,2021), ql.Date(25,1,2022))
couponsLeg = ql.Leg([cf1, cf2, cf3, cf4])
newBond=ql.Bond(0,ql.UnitedStates(),ql.Date(25,1,2018),couponsLeg)
```

Or, better yet, you can simply use the `AmortizingFixedRateBond` class:

```
notionals = [100,100,100,50]
schedule = ql.MakeSchedule(ql.Date(25,1,2018), ql.Date(25,1,2022), ql.Period('1y'))
bond = ql.AmortizingFixedRateBond(0, notionals, schedule, [0.03], ql.Thirty360())
```

Both would output the same cashflows, which I believe is what you want:

January 25th, 2019 3.0 January 25th, 2020 3.0 January 25th, 2021 3.0 January 25th, 2021 50.0 January 25th, 2022 1.5 January 25th, 2022 50.0

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.