1

I would like to calculate the price of a 5-year zero-coupon bond at 10% interest with a face value of $1000. I expect such a bond to be priced at $620.92 since $620.92 = 1000/((1.10)^5).

Here's my attempt in Python (Version 3.9.12) using QuantLib (Version 1.29), which returns a price of $60.67, not $620.92.

import QuantLib as ql

# Set up the bond parameters

face_value = 1000
interest_rate = 0.10
maturity_date = ql.Date(9, 3, 2028) # Maturity in 5 years
issue_date = ql.Date(9, 3, 2023) # Issue date today

# Create a bond object

bond = ql.ZeroCouponBond(0, ql.NullCalendar(), face_value, maturity_date)

# Set up the bond engine

spot_curve_handle = ql.YieldTermStructureHandle(ql.FlatForward(issue_date, interest_rate, ql.Actual365Fixed()))
bond_engine = ql.DiscountingBondEngine(spot_curve_handle)

# Assign the bond engine to the bond object

bond.setPricingEngine(bond_engine)

# Calculate the bond price

price = bond.cleanPrice()

print(f"The price of the bond is: {price:.2f}")

I also see that

bond.NPV() 

returns $606.20, not $620.92.

How can I modify the code above so that it returns that "textbook" bond price of $620.92?

D I
  • 15
  • 4

1 Answers1

3

Change the bond set up including compounding

qflatforw = ql.FlatForward(issue_date, interest_rate, ql.ActualActual(ql.ActualActual.ISMA), ql.Compounded,ql.Annual)

spot_curve_handle = ql.YieldTermStructureHandle(qflatforw)

bond.NPV() 620.9213230591549

To get the other prices define settlement date

ql.Settings.instance().evaluationDate = ql.Date(9, 3, 2023)
price = bond.cleanPrice()
print(f"The price of the bond is: {price:.2f}")

The price of the bond is: 62.09

bond.dirtyPrice()

62.0921323059155

Robert
  • 5,038
  • 1
  • 25
  • 43
  • Thanks, Robert! I've marked your answer as the approved answer. I tried to upvote it but I don't have the requisite 15 reputation points to do so. – D I Mar 13 '23 at 17:46
  • By the way @Robert, do you know why in this case bond.cleanPrice() give a different answer than bond.NPV()? I was expecting they'd be pretty much the same as in this case: https://stackoverflow.com/questions/68542560/difference-between-clean-price-dirty-price-and-npv-using-quantlib-python – D I Mar 13 '23 at 18:07
  • See the code added in the edit version. – Robert Mar 15 '23 at 12:33