0
$\begingroup$

I'm trying to price a fixed rate bond with ex-dividend date using Python QuantLib. This is a feature of UK Gilts.

On regular days, I'm able to get the correct accrued interest, but on days in the ex-dividend period, I'm unable to determine the correct accrued interest. Any help is appreciated.

Below is my code

import QuantLib as ql
import datetime as dt
import numpy as np
import pandas as pd

#ISIN: GB00B54QLM75
issue_date=ql.Date(22, 10, 2009)
maturity_date=ql.Date(22, 1, 2060)
first_cpn_date=ql.Date(22, 1, 2010)
last_cpn_date=ql.Date(22, 7, 2059)
tenor=ql.Period(ql.Semiannual)
calendar=ql.UnitedKingdom()
business_convention=ql.Unadjusted
termination_business_convention=ql.Unadjusted
date_generation=ql.DateGeneration.Forward
end_of_month=False
coupon = .04

fbSchedule=ql.Schedule(issue_date, 
                    maturity_date,
                    tenor,
                    calendar,
                    business_convention,
                    termination_business_convention,
                    date_generation,
                    end_of_month,
                    first_cpn_date,
                    last_cpn_date)
sch = [x for x in fbSchedule]
fbSchedule = ql.Schedule(
    sch,
    calendar,
    business_convention,
    termination_business_convention,
    tenor,
    date_generation,
    end_of_month,
    [True] * (len(sch)-1)
)
cpns = [coupon]

settle_days=1
face_amt = 100.
rdm_amt = 100.
fixedRateBond = ql.FixedRateBond(
    settle_days, 
    face_amt,
    fbSchedule,
    cpns,
    ql.ActualActual(ql.ActualActual.ISMA),
    business_convention,
    rdm_amt,
    issue_date
    )

print(fixedRateBond.accruedAmount(ql.Date(24, 3, 2023)))
#QL: 0.6740331491712714, Blbg: 0.67403
print(fixedRateBond.accruedAmount(ql.Date(14, 7, 2023)))
#QL: 1.9116022099447516, Blbg: -0.08840

Edit: I don't think this is a duplicate of Negative Accrued for treasury bonds? as a method to determine negative AI is not described

$\endgroup$
0

1 Answer 1

4
$\begingroup$

Pass the ex-coupon information to the bond constructor. The library has no way to know otherwise.

payment_calendar = ql.UnitedKingdom()
ex_coupon_period = ql.Period(7, ql.Days)
ex_coupon_calendar = ql.UnitedKingdom()

fixedRateBond = ql.FixedRateBond(
    settle_days,
    face_amt,
    fbSchedule,
    cpns,
    ql.ActualActual(ql.ActualActual.ISMA),
    business_convention,
    rdm_amt,
    issue_date,
    payment_calendar,
    ex_coupon_period,
    ex_coupon_calendar,
)

print(fixedRateBond.accruedAmount(ql.Date(24, 3, 2023)))
# 0.6740331491712714
print(fixedRateBond.accruedAmount(ql.Date(14, 7, 2023)))
# -0.08839779005525017
$\endgroup$

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