0
$\begingroup$

enter image description here

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

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

1 Answer 1

6
$\begingroup$

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)

enter image description here

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()
$\endgroup$
4
  • $\begingroup$ Sorry for asking this question later. @David Duarte, which field names would extract the 'discount factors' and the 'discounted cashflows' in this instance? $\endgroup$
    – ccc
    Commented Aug 5, 2022 at 22:27
  • $\begingroup$ Those fields are not in the bond object but you could just get the discount factor for each payment date from the yield curve and multiply that by the cashflow amount to get the pv $\endgroup$ Commented Aug 6, 2022 at 7:16
  • $\begingroup$ thanks for clarifying that. Do you perhaps have an example that can work for the snippet Python code above? $\endgroup$
    – ccc
    Commented Aug 6, 2022 at 11:57
  • $\begingroup$ thank you it worked! $\endgroup$
    – ccc
    Commented Aug 7, 2022 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.