Classifying QuantLib Bond Cash Flows as Coupons or Redemptions
Summary
The document asks how to distinguish interest and principal payments in cash-flow schedules generated for amortizing floating-rate bonds with QuantLib’s Python interface. The example shows multiple payments on shared dates across a series of dates, and notes that manually checking a large bond set is impractical.
The accepted response recommends trying to cast each cash flow to a coupon type: a successful coupon cast identifies an interest payment, while a failed coupon cast indicates a principal redemption. It also suggests checking fixed-rate or floating-rate coupon casts to access coupon-specific information, and using the bond’s redemptions inspector. The answer is a concise API hint rather than a complete implementation guide; exact casting behavior and available methods may depend on the QuantLib Python bindings and version.
Key ideas
- A coupon cast can help distinguish coupon payments from principal redemptions.
- Fixed-rate and floating-rate coupon casts can expose additional payment details.
- The bond redemptions inspector offers another way to identify principal payments.
- The response does not provide a complete batch-processing example or discuss binding-version differences.
Tags
Full text
# In Python QuantLib how to identify Principal and Interest cashflows?
# In Python QuantLib how to identify Principal and Interest cashflows?
I am fairly new to QuantLib Python. I have generated the following cashflows from one AmortizingFloatingBond from QuantLib Python. But I am not able to identify which ones are Interest payments and which ones are Principal; I have more than 450 bonds and it is not possible to manually look into each. Is there any tag for Principal and Interest in the QuantLib output?
```
for j, cf in enumerate(amortizingfloatbond.cashflows()):
print((j + 1), cf.date(), cf.amount())
1 October 2nd, 2020 455855.3007039195
2 October 2nd, 2020 327494.6000000001
3 October 4th, 2021 368553.92597433936
4 October 4th, 2021 327494.6
5 October 3rd, 2022 260478.18044824633
6 October 3rd, 2022 327494.6
7 October 2nd, 2023 174560.1025981066
8 October 2nd, 2023 327494.6
9 October 2nd, 2024 88260.35700473993
10 October 2nd, 2024 327494.6
```
Will really appreciate any inputs. Thanks in advance.
## Answer by Dimitri Vulis (score 2, accepted)
https://quant.stackexchange.com/a/66063
Try casting, something like
```
c = as_coupon(cf)
if not c.__nonzero__():
print "principal redemption"
```
You can likewise attempt casting the `cf` to `as_fixed_rate_coupon(cf)` or to `as_floating_rate_coupon(cf)`, and if they work, then access other useful info. Also, `redemptions` is another available inspector.
Related question: 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 itShown 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.