A simple floating rate bond pricer in QuantLib using a flat interest rate curve.
import QuantLib as ql
bond properties:
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:
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
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)
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)
bond_engine = ql.DiscountingBondEngine(discounting_term_structure)
floating_bond.setPricingEngine(bond_engine)
print (floating_bond.NPV(), floating_bond.cleanPrice(), floating_bond.dirtyPrice())