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

• Have you tried the cashflows and redemptions inspectors for c in fixedRateBond.cashflows(): print('%18s %f' % (c.date(), c.amount())) Jun 5, 2020 at 1:07

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)