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$
  • $\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 '19 at 12:00
0
$\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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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