2 Comments
User's avatar
Jim's avatar

Hi Luigi,

In this chapter you mentioend that "This is because the bond methods don’t rely on the reference date of the curve (which doesn’t always equal the evaluation date) but on the global evaluation date." but when I realize the bond by code like below. It seems the bond method relay on the "today" I passed it to since I will get a different value when the today is different with reference day.

bond = ql.FixedRateBond(0, face_amount, schedule, coupon, day_count)

bond_price = 102.0 + 7/32

bond_yield = bond.bondYield(bond_price, day_count,

ql.Compounded, ql.Semiannual, today)

calculated_clean_price = bond.cleanPrice(bond_yield, day_count,

ql.Compounded, ql.Semiannual, today)

dirty_price = bond.dirtyPrice(bond_yield, day_count,

ql.Compounded, ql.Semiannual, today)

accrued_interest = bond.accruedAmount(today)

However, I passed the "today" to the flatforward curve as well.

flat_curve = ql.FlatForward(today, ql.QuoteHandle(ql.SimpleQuote(bond_yield)),

ql.ActualActual(ql.ActualActual.ISDA), ql.Compounded, ql.Semiannual)

discount_curve_handle = ql.YieldTermStructureHandle(flat_curve)

bond.setPricingEngine(ql.DiscountingBondEngine(discount_curve_handle))

print(bond.cleanPrice())

print(bond.accruedAmount(today))

print(bond.dirtyPrice())

I found even i use today as parameter to calculte the accured interest, it still use the refference date.

is this a bug or somehow you made it on purpose? Thanks!

Expand full comment
Luigi Ballabio's avatar

Unfortunately there's no way to format code here in the comments, so writing examples is more than a bit awkward.

Anyway: some of the methods of the bonds, namely, those that don't use a pricing engine, can take an explicit settlement date; for instance the versions of cleanPrice and dirtyPrice based on a yield. Note that it's the settlement date, not the evaluation date; the settlement date is usually 3 business days later. The same goes for accruedAmount; the result will change based on the settlement date you're passing. On the other hand, if you call accruedAmount or cleanPrice or dirtyPrice without passing a settlement date, they will calculate it based on the global evaluation date.

The today you pass to the flat curve, instead, won't matter, because the coupons are discounted to the settlement date of the bond, which is calculated based on the evaluation date. If you pass today+1 to the flat curve and keep the global evaluation date equal to today, you should get the same results.

More information (with code) is available at <https://www.quantlibguide.com/Vanilla%20bonds.html>.

Expand full comment