Reputation: 389
I used QuantLib Python to price a fixed rate bond.
I used ql.ActualActual(ql.ActualActual.ISMA, schedule)
to ensure that cash flows are the same for each coupon payment period.
For discounting, I used ql.Actual360()
as day count convention.
My codes are as follows:
import QuantLib as ql
valuationDate = ql.Date(30, 6, 2020)
ql.Settings.instance().evaluationDate = valuationDate
schedule = ql.Schedule(ql.Date(7, 5, 2016), ql.Date(15, 8, 2024), ql.Period(ql.Semiannual), ql.NullCalendar(), ql.Following, ql.Following, ql.DateGeneration.Forward, True)
fixedRateBond = ql.FixedRateBond(0, 100, schedule, [0.05], ql.ActualActual(ql.ActualActual.ISMA, schedule))
curve = ql.FlatForward(valuationDate, ql.QuoteHandle(ql.SimpleQuote(0.05)), ql.Actual360(), ql.Compounded)
handle = ql.YieldTermStructureHandle(curve)
bondEngine = ql.DiscountingBondEngine(handle)
fixedRateBond.setPricingEngine(bondEngine)
irr = fixedRateBond.bondYield(fixedRateBond.NPV(), ql.Actual360(), ql.Compounded, ql.Semiannual, valuationDate)
print('NPV:', fixedRateBond.NPV())
print('IRR:', irr)
print('Clean Price:', fixedRateBond.cleanPrice(irr, ql.Actual360(), ql.Compounded, ql.Semiannual, valuationDate))
print('Dirty Price:', fixedRateBond.dirtyPrice(irr, ql.Actual360(), ql.Compounded, ql.Semiannual, valuationDate))
print('Accrued Interest:', fixedRateBond.accruedAmount(ql.Date(30, 6, 2020)))
The results I get are as follows:
NPV: 100.59728065053405
IRR: 0.04743504524230957
Clean Price: 100.59728133098947
Dirty Price: 101.3309769831634
Accrued Interest: 0.7336956521739156
As far as I know, the NPV should be the same as the dirty price. However, there is a minor difference that I cannot get rid of. Grateful if someone could explain where I went wrong.
And when I subtract the clean price from the dirty price to manually obtain the accrued interest, the answer is 0.7336956521739211, which differs slightly from QuantLib's accruedAmount
function. Can someone explain where I went wrong please?
Thanks.
Upvotes: 0
Views: 1918