The price of a promise
Worked examples
Read the claim, then run it and check the machine agrees. One at a time — nothing here is taken on trust.
import math
df_from_rate = lambda z, t: math.exp(-z * t)
rate_from_df = lambda df, t: -math.log(df) / t
df1 = df_from_rate(0.048, 1.0)
print("price of $1 in 1y at z = 4.8%:", round(df1, 6))
print("round-trip back to the rate: ", rate_from_df(df1, 1.0))
print("price of $1 in 2y at z = -0.5%:", round(df_from_rate(-0.005, 2.0), 6), " -> above 1.00")
One price, two languages. The round trip is exact because e^x and ln x are inverses — lesson 0.1's whole point. And at a −0.5% rate the promise costs 1.010050: more than a dollar today. Negative rates aren't an error state; they're a df above one. (2y at −0.5% was a perfectly ordinary German quote in 2020.)
import QuantLib as ql
today = ql.Date(9, 7, 2026)
dates = [today, today + ql.Period(1, ql.Years), today + ql.Period(2, ql.Years)]
dfs = [1.0, 0.96, 0.92] # the prices of $1: now, in 1y, in 2y
curve = ql.DiscountCurve(dates, dfs, ql.Actual365Fixed())
print("df(0) =", curve.discount(0.0))
print("df(1y) =", curve.discount(dates[1]))
print("df(1.5) =", round(curve.discount(1.5), 6), " (filled in between nodes - lesson 1.3's subject)")
ql.DiscountCurve is barely more than the two lists you handed it:
dates and the prices of $1 on those dates. The first node must be
(today, 1.0) — sanity property #1 baked into the constructor. Between
the nodes the curve interpolates; how it fills those gaps is a
genuine modelling decision that gets its own lesson.
import QuantLib as ql
today = ql.Date(9, 7, 2026)
d1, d2 = today + ql.Period(1, ql.Years), today + ql.Period(2, ql.Years)
curve = ql.DiscountCurve([today, d1, d2], [1.0, 0.96, 0.92], ql.Actual365Fixed())
# a 2y bond, 6% annual coupon on 100 notional: pays 6 at 1y, 106 at 2y
price = 6.0 * curve.discount(d1) + 106.0 * curve.discount(d2)
print(f"price = 6 x {curve.discount(d1)} + 106 x {curve.discount(d2)} = {price:.2f}")
103.28, from two multiplications and an addition. No yield, no model of future rates, no bond formula: each cash flow is just an amount times the quoted price of $1 on its date. This is claim two from the overview doing real work — and it's exactly how you'll price a 5-year bond in the challenge.
Check the concept
One question at a time. Unsure? Revisit the lecture, then answer.
The challenge
Pass the quiz to unlock the challenge — your code will still be waiting here.