1
$\begingroup$

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)

$\endgroup$
1
  • $\begingroup$ My purpose is to construct a bond with advanced principle payment (I have added my code for reference). I have read the C++ code, I am not clear whether I used the ql.Leg() correctly. $\endgroup$
    – user38862
    Feb 19, 2019 at 12:00

1 Answer 1

1
$\begingroup$

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

$\endgroup$

Your Answer

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

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