|
From: Conrad C. <con...@gm...> - 2021-08-13 14:17:24
|
Hi Jian, The content in this link should provide some clarity to your inquiry. https://quant.stackexchange.com/questions/12707/pricing-a-fixedratebond-in-quantlib-yield-vs-termstructure/12715#12715 <https://quant.stackexchange.com/questions/12707/pricing-a-fixedratebond-in-quantlib-yield-vs-termstructure/12715#12715> Regards, Conrad Cole https://www.linkedin.com/in/conradcole/ <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttps-3A__www.linkedin.com_in_conradcole_%26d%3DDwMFaQ%26c%3Dj-EkbjBYwkAB4f8ZbVn1Fw%26r%3DgdVyBBPVWs13utXwz8gnZm_nAAP9QAdSnii2IJqmorA%26m%3DBB5ue-rDsok8MXDHSKztDytEfiZR8fiFaU16zeBpTCg%26s%3D0G2tyRZA_g1nxUpHxp-orprHIXmcHhxldPFnQ7y4rXA%26e%3D&data=04%7C01%7Chyman%40adobe.com%7C271ab0ec50a940c1bcf008d931b3c0a7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637595470360539602%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=SPf8o8QVSS8Eurt2suoBz3Rx5QskZBA7NK9crCvTu2c%3D&reserved=0> https://github.com/darnoceloc <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttps-3A__github.com_darnoceloc%26d%3DDwMFaQ%26c%3Dj-EkbjBYwkAB4f8ZbVn1Fw%26r%3DgdVyBBPVWs13utXwz8gnZm_nAAP9QAdSnii2IJqmorA%26m%3DBB5ue-rDsok8MXDHSKztDytEfiZR8fiFaU16zeBpTCg%26s%3DN5brSSbSQne5QmmF2BkZBY7Pc-1us2Kn_UJGgM6In4w%26e%3D&data=04%7C01%7Chyman%40adobe.com%7C271ab0ec50a940c1bcf008d931b3c0a7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637595470360549598%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=uTDE4OAmMOM5JclPtkAz5gZrd0laAxb2T1hb%2FEqArgc%3D&reserved=0> On 8/13/21 9:52 AM, jian Xu wrote: > 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) > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users |