0% found this document useful (0 votes)
473 views2 pages

Pricing A Floating Bond in Quantlib Using Python - Stack Overflow

The document is a question posted on Stack Overflow asking how to price a floating rate bond in Python using the QuantLib library. The question details a bond with a 4 year maturity, 10% LIBOR rate and 0% spread. The OP is getting a price of 99.54 instead of the expected 100 when discounting at the 10% rate. The top answer explains that the discrepancy is due to the coupon rates being fixed using a different day count convention (Actual/360) than the provided payment convention (30/360). Creating a custom LIBOR index with an internal 30/360 day count yields an exact price of 100.

Uploaded by

smartin1970
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
473 views2 pages

Pricing A Floating Bond in Quantlib Using Python - Stack Overflow

The document is a question posted on Stack Overflow asking how to price a floating rate bond in Python using the QuantLib library. The question details a bond with a 4 year maturity, 10% LIBOR rate and 0% spread. The OP is getting a price of 99.54 instead of the expected 100 when discounting at the 10% rate. The top answer explains that the discrepancy is due to the coupon rates being fixed using a different day count convention (Actual/360) than the provided payment convention (30/360). Creating a custom LIBOR index with an internal 30/360 day count yields an exact price of 100.

Uploaded by

smartin1970
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Pricing a Floating Bond in quantlib using Python - Stack Overflow http://stackoverflow.com/questions/15273797/pricing-a-floating-bond-i...

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no
×
registration required.

Pricing a Floating Bond in quantlib using Python

I am trying to price a very basic floating rate bond in python using the Quantlib (v1.2) SWIG wrapper. I
modified the example included with the documentation.

My bond has a 4 year maturity. The libor is set to 10% and the spread of the bond is 0. My question is if I
am discounting at the rate of 10%, why isn't the PV of the bond 100? I am getting a value of 99.54.

Thanks!

from QuantLib import *

frequency_enum, settle_date = 4, Date(5, 1, 2010)
maturity_date = Date(5, 1, 2014)
face_amount = 100.0
settlement_days = 0
fixing_days = 0

calendar = NullCalendar()
settle_date = calendar.adjust(settle_date)
todays_date = calendar.advance(settle_date, ‐fixing_days, Days)
Settings.instance().evaluationDate = todays_date

rate = 10.0 / 100.0

flat_forward = FlatForward(settle_date,
                           rate,
                           Thirty360(),
                           Compounded,
                           frequency_enum)

discounting_term_structure = RelinkableYieldTermStructureHandle(flat_forward)
index_term_structure = RelinkableYieldTermStructureHandle(flat_forward)

index = USDLibor(Period(3, Months), index_term_structure)

schedule = Schedule(settle_date,
                    maturity_date, Period(frequency_enum),
                    NullCalendar(),
                    Unadjusted, Unadjusted,
                    DateGeneration.Forward, False)

floating_bond = FloatingRateBond(settlement_days,
                                 face_amount,

python quantlib quantlib-swig

asked Mar 7 at 14:30


ducky
61 6

1 Answer

The coupons rates are fixed using the USDLibor day counter (that is, Actual/360) which doesn't match the
payment day counter you provided (30/360). You can see it by inspecting the coupons:

cfs = floating_bond.cashflows()
coupons = [ as_coupon(c) for c in cfs[:‐1] ] # the last one is the redemption
print [ (c.rate(), c.accrualPeriod()) for c in coupons ]

which gives you T = 0.25 for all coupons, but rates lower than 10%.

To get the price you want, you have to match rate and accrual period. One way is to pass Actual360() as

1 of 2 7/12/2013 8:20 PM
Pricing a Floating Bond in quantlib using Python - Stack Overflow http://stackoverflow.com/questions/15273797/pricing-a-floating-bond-i...

the bond day counter, which gives a price of 100.002 on my machine (I haven't investigated further, but
the discrepancy might be due to the end date for the LIBOR fixing, which is determined using the USD
calendar and might not match the end of the coupon exactly). Another way is to create a custom LIBOR
index with an internal 30/360 day counter; I haven't tried this myself, but you can do it by creating an
appropriate instance of the IborIndex class.

answered Mar 8 at 15:54


Luigi Ballabio
436 3 7

Thanks a lot. I created a custom index and I got an exact result of 100.0! Custom index is: index =
IborIndex('USD Libor', Period(3, Months), settlement_days, USDCurrency(), NullCalendar(),
Unadjusted, False, Thirty360(), index_term_structure) – ducky Mar 8 at 20:52

Not the answer you're looking for? Browse other questions tagged python quantlib

quantlib-swig or ask your own question.

2 of 2 7/12/2013 8:20 PM

You might also like