|
From: jian Xu <jia...@gm...> - 2021-08-13 13:53:15
|
One thing I noticed is that if I set "day_count" to ql.ActualActual() instead of ql.ActualActual(ql.ActualActual.ISMA), then the dirty price matches the npv exactly. This is very strange. The "day_count" variable is consistently used in the bond's constructor, dirtyPrice(), and InterestRate's constructor. Why would ql.ActualActual.ISMA causing dirty price and the npv to be different? Am I missing something? On Fri, Aug 13, 2021 at 7:57 AM jian Xu <jia...@gm...> wrote: > > Hi, > I saw some difference between a bond's dirty price and the discounted > cashflow to the settlement date. Cannot figure out why. > > For example, in the following code, the dirty price is 103.4815, while > my discounted cashflow is 103.4674, why? Thanks a lot. > > =============================== > import QuantLib as ql > > ## setup the security > schedule = ql.MakeSchedule(effectiveDate = ql.Date(30, 6, 2018), > terminationDate = ql.Date(30, 6, 2023), > tenor = ql.Period(2), > calendar = > ql.UnitedStates(ql.UnitedStates.GovernmentBond), > convention = ql.Unadjusted, > terminalDateConvention=ql.Unadjusted, > rule = ql.DateGeneration.Backward, > endOfMonth = True) > > day_count = ql.ActualActual(ql.ActualActual.ISMA) # US market > convention, not the QuantLib default !!! > face = 100 > redemption = 100 > issue_date = ql.Date(2, 7, 2018) > days_settle = 1 > coupon = 2.625/100 > payment_convention = ql.Unadjusted > bond = ql.FixedRateBond(days_settle, > face, > schedule, > [coupon], > day_count, > payment_convention, > redemption, > issue_date) > > ## Dirty price > settle_date = ql.Date(5, 10, 2021) > yld = 0.01 > freq = ql.Semiannual > print(bond.dirtyPrice(yld, day_count, ql.Compounded, freq, settle_date)) > > ## my discount cash flow > disc = ql.InterestRate(yld, day_count, ql.Compounded, freq) > npv = 0 > for cf in bond.cashflows(): > if cf.date() < settle_date: > continue > df = disc.discountFactor(settle_date, cf.date()) > npv += cf.amount() * df > print(npv) |