QuantLib Python: How to calculate the price of a zero coupon bond?


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


# Calculate the bond price

price = bond.cleanPrice()

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

I also see that


returns $606.20, not $620.92.

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

Asked By: D I



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)


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



Answered By: Robert
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.