A simple floating rate bond pricer in QuantLib using a flat interest rate curve.

In [1]:
import QuantLib as ql

bond properties:

In [11]:
frequency = 4
settle_date = ql.Date(5, 1, 2010)
maturity_date = ql.Date(5, 1, 2014)
face_amount = 100.0
settlement_days = 0
fixing_days = 0

calendar definitions:

In [12]:
calendar = ql.NullCalendar()
settle_date = calendar.adjust(settle_date)
todays_date = calendar.advance(settle_date, -fixing_days, ql.Days)
ql.Settings.instance().evaluationDate = todays_date
In [13]:
interest_rate = 0.1

flat_forward = ql.FlatForward(settle_date,
                           interest_rate,
                           ql.Thirty360(),
                           ql.Compounded,
                           frequency)

discounting_term_structure = ql.RelinkableYieldTermStructureHandle(flat_forward)
index_term_structure = ql.RelinkableYieldTermStructureHandle(flat_forward)

index = ql.USDLibor(ql.Period(3, ql.Months), index_term_structure)
In [14]:
schedule = ql.Schedule(settle_date,
                    maturity_date, ql.Period(frequency_enum),
                    ql.NullCalendar(),
                    ql.Unadjusted, ql.Unadjusted,
                    ql.DateGeneration.Forward, False)

floating_bond = ql.FloatingRateBond(settlement_days,
                                 face_amount,
                                 schedule,
                                 index,
                                 ql.Thirty360(),
                                 ql.Unadjusted,
                                 fixing_days,
                                 [],   # Gearings
                                 [0],  # Spreads
                                 [],      # Caps
                                 [],      # Floors
                                 False,    # Fixing in arrears
                                 face_amount,
                                 settle_date)
In [15]:
bond_engine = ql.DiscountingBondEngine(discounting_term_structure)
floating_bond.setPricingEngine(bond_engine)

print (floating_bond.NPV(), floating_bond.cleanPrice(), floating_bond.dirtyPrice())
99.54335454268231 99.5433545426823 99.5433545426823
In [ ]:
 
In [ ]: