Skip to content
All library documents

Inspecting Bond Cash Flows and Present Values in QuantLib

Article Quant Q&A · Author: Jose Andres Riveros

Summary

The document explains how to inspect the scheduled cash flows of a bond created in QuantLib. Iterating through the bond’s cash-flow objects exposes each payment date and amount, making coupon payments and principal redemption visible. For fixed-rate coupons, additional fields such as accrual dates, day-count convention, nominal value, and interest rate can be collected into a tabular view.

The answer also shows how to calculate discount factors from a yield curve and multiply them by cash-flow amounts to obtain discounted values. Its examples demonstrate the fields and output structure, rather than provide a full bond-pricing treatment. Coupon-specific attributes do not apply to a redemption cash flow, so the example excludes the final cash-flow object when accessing those fields; users should account for their bond’s cash-flow types and schedule.

Key ideas

  • A bond’s cash-flow objects expose payment dates and amounts.
  • Coupon objects can provide accrual and rate details beyond the basic payment amount.
  • Coupon-specific fields are unavailable on a principal redemption cash flow.
  • Discounted cash flows can be calculated by multiplying each amount by its yield-curve discount factor.
  • The example organizes coupon details and present values in a table.

Tags

Full text
# Answer by David Duarte (score 6, accepted)


# how can i see the cashflows of a specific bond created in quantlib in Python? this is the code i have, how should i change it












This is the code i have, what would be the way to see the cashflows of this specific bond i created

## Answer by David Duarte (score 6, accepted)

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

As Dimitri said, you can use the cashflows inspectors:

```
for cf in bond.cashflows():
    print(cf.date().ISO(), cf.amount())
```

2019-07-30 1.4999999999999902 2020-01-30 1.4999999999999902 2020-07-30 1.4999999999999902 (...) 2029-01-30 1.4999999999999902 2029-07-30 1.4999999999999902 2030-01-30 1.4999999999999902 2030-01-30 100.0

This way your cashflows will have a date and an amount, and you will see both the interest and redemptions.

If you need a bit more detail, you can use the `ql.as_coupon`, `ql.as_fixed_rate_coupon` or `ql.as_floating_rate_coupon` methods to extract additional fields:

```
import pandas as pd
fields = [
    'accrualDays', 'accrualEndDate', 'accrualPeriod', 'accrualStartDate',
    'amount',  'date', 'dayCounter', 'interestRate', 'nominal',  'rate'
]

data = []
for cf in list(map(ql.as_fixed_rate_coupon, bond.cashflows()))[:-1]:
    data.append({fld: eval(f"cf.{fld}()") for fld in fields})
pd.DataFrame(data)
```

Here I made a list of the map to avoid the last coupon because the redemption cashflows does not have these additional fields and will through an error.

(EDIT after comment)

If you wanted the discount factor and discouted cashflow, you could do something like this:

```
yc = ql.FlatForward(2, ql.TARGET(), 0.05, ql.Actual360())

data = []
for cf in list(map(ql.as_fixed_rate_coupon, bond.cashflows()))[:-1]:
    row = {fld: eval(f"cf.{fld}()") for fld in fields}
    row['df'] = yc.discount(row['date'])
    row['pv'] = row['df'] * row['amount']
    data.append(row)
pd.DataFrame(data).head()
```

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.