On 3 January 2022 the 5-year US Treasury par yield was 1.37%; on 9 October 2026 it is 5.02%. A five-year swap struck at the old rate is worth 158,401 to the side that pays fixed, on a notional of one million, and one more basis point of interest rate adds another 390 to it. This topic builds the machinery that turns a curve into those numbers.
From a par curve to discount factors
Where we are. The Python course priced a bond by discounting its cash flows, and read yields and curves. This skill goes from there to the products banks actually trade. The first step is to write a curve in the form every later topic uses: a list of discount factors.
P_i is the price today of 1 paid in i years. If P_5 = 0.80, a promise of 100 in five years costs 80 today. Pricing anything that pays fixed amounts at known dates is a sum of amounts times discount factors, so once you have the P_i you can price almost everything.
Markets do not quote discount factors. The US Treasury quotes par yields: the coupon rate at which a bond of that maturity costs exactly its face value of 1. A 3-year bond with an annual coupon c_3 pays c_3 at the end of each of the three years and 1 at the end of the third, and costs 1. Written with discount factors, that sentence is an equation.
Worked example 1. *Problem:* the par rates of years 1, 2 and 3 are 2%, 3% and 4%. What are the discount factors? *Plan:* year 1 has no earlier factor; each later year uses the sum of the factors found so far. *Steps:* below.
par = np.array([0.02, 0.03, 0.04])discount = bootstrap_discount(par)1print(discount.round(6).tolist())2print([round(float(par[k] * discount[:k + 1].sum() + discount[k]), 6) for k in range(3)])
[0.980392, 0.942319, 0.887588] [1.0, 1.0, 1.0]
- 1One factor per year, found one after the other.
- 2Every par bond must cost 1.
*Check:* P_1 = 1 / 1.02 = 0.980392; P_2 = (1 − 0.03 × 0.980392) / 1.03 = 0.942319; P_3 = (1 − 0.04 × (0.980392 + 0.942319)) / 1.04 = 0.887588. The second line prices the three par bonds with these factors and gets 1.0 each time. *What to notice:* the factors fall faster than the rates alone suggest because each year's coupon is discounted with the earlier factors. A flat par curve of 5% gives P_n = 1 / 1.05^n; a rising one gives smaller factors further out.
Treasury quotes six tenors (1, 2, 3, 5, 7 and 10 years). A bond that pays once a year needs a par rate for every year, so the lab first joins the quoted points with straight lines: that is interpolate_par. Treasury par yields are really quoted with half-yearly coupons; the lab uses annual ones so that every formula stays short.
Forward rates
A discount factor for five years tells you what five years of waiting costs, but not what year five alone costs. The forward rate f_i is the interest rate for year i that the curve implies today: the rate at which you could lock in today to lend from the end of year i − 1 to the end of year i.
Worked example 2. *Problem:* what forward rates are hidden in the curve of example 1? *Plan:* divide each factor by the next one and subtract 1. *Steps:* below.
forwards = forward_rates(discount)1print(forwards.round(6).tolist())print(round(float(np.prod(1 + forwards)), 6), round(float(1 / discount[-1]), 6))
[0.02, 0.040404, 0.061662] 1.126649 1.126649
- 1The rate implied for each single year.
*Check:* the forwards are 2.00%, 4.04% and 6.17%, while the par rates are 2%, 3% and 4%. Compounding the three forwards gives 1.126649, the same as 1 / P_3. *What to notice:* a rising curve means the future years cost more than the average: the forward for year 3 is far above the 3-year par rate. Forwards are what the market expects plus a price for waiting, and they are the building block of every rate product.
A swap is two legs
An interest-rate swap is an agreement to exchange interest payments on a notional amount that is never paid. One side pays a fixed rate K agreed today; the other pays the floating rate, which is reset each year to the market rate. The side that pays fixed is called the *payer*; the other is the *receiver*.
The fixed leg is a bond-like stream: K per year for n years, worth K times the annuity P_1 + ... + P_n. The floating leg is worth 1 − P_n per unit of notional: a floating-rate bond that pays the market rate is always worth its face value, so receiving the floating payments for n years is worth 1 now minus the notional you would get back at the end, P_n.
Worked example 3. *Problem:* on the curve of example 1, what is the par swap rate for 3 years, and what is a 3-year swap with a fixed rate of 3.5% on one million worth to each side? *Plan:* compute the annuity, the two legs and subtract. *Steps:* below.
print(round(annuity(discount, 3), 6), round(swap_rate(discount, 3), 6), round(swap_rate(discount, 2), 6))1print(round(1e6 * (1 - discount[2]), 2), round(1e6 * 0.035 * annuity(discount, 3), 2))2print(round(swap_value(discount, 0.035, 3, 1e6), 2), round(swap_value(discount, 0.035, 3, 1e6, pay_fixed=False), 2))print(round(swap_value(discount, swap_rate(discount, 3), 3, 1e6), 6))
2.810299 0.04 0.03 112411.96 98360.46 14051.49 -14051.49 0.0
- 1The annuity and the par swap rates.
- 2The floating and the fixed leg of the 3.5% swap.
*Check:* the annuity is 2.810299. The par swap rate for 3 years is 4.00% and for 2 years 3.00%: they equal the par rates we started from, as they must, because a swap is a bond in disguise. The floating leg of the 3.5% swap is worth 112,411.96 and the fixed leg 98,360.46, so the payer of fixed gains 14,051.49 and the receiver loses the same amount. At the par swap rate the value is 0. *What to notice:* the 3.5% swap pays less fixed than the market rate of 4%, so it is an asset to the payer: the gain is about 0.5% times the annuity times the notional.
Banks build their swap curve from overnight rates (SOFR) and swap quotes, not from Treasuries, and they add small adjustments. The mechanics you write here are the same; only the input curve changes. Using the Treasury curve keeps the lab on real, public data.
What one basis point does
A trader who owns a swap asks the same question about every position: *how much do I gain or lose if rates move a little?* The standard answer is the DV01: the change in value for a rise of one basis point (0.0001, a hundredth of a percent) in the curve. It is found by bumping the quoted rates, building the curve again, and valuing the same swap on both curves.
Worked example 4. *Problem:* what is the DV01 of the 3.5% swap of example 3 for the payer of fixed? *Plan:* shift all par rates by 0.0001, bootstrap again, and take the difference of the two values. *Steps:* below.
print(round(swap_dv01(par, 0.035, 3, 1e6), 2))1print(round(swap_value(bootstrap_discount(par + 0.0001), 0.035, 3, 1e6) - swap_value(discount, 0.035, 3, 1e6), 2))
278.28 278.28
- 1The function and the same thing written out.
*Check:* both lines give 278.28: a rise of one basis point in all rates adds 278 to the value of this swap for the payer of fixed, who is paying a rate that is now further below the market. *What to notice:* rates up helps the payer of fixed, and the amount is close to the annuity (2.81) times the notional times 0.0001 (281), a little less because every discount factor also falls.
The Treasury curve as a swap curve
Worked example 5. *Problem:* build the discount curve and the swap rates for three days: 3 January 2022, 3 July 2023 and the last day of the file, and value a swap struck in January 2022 on the last day. *Plan:* study interpolates and bootstraps each day, reads the 2-, 5- and 10-year swap rates and the forwards, and values a 5-year swap struck at the January 2022 rate. *Steps:* below.
treasury = load_treasury()out = study(treasury)1for date, curve in out["curves"].items(): print(date, [round(curve[k], 4) for k in ("swap_2y", "swap_5y", "swap_10y")], [round(curve["forwards"][i], 4) for i in (0, 4, 9)])print(round(out["value"], 2), round(out["dv01"], 2), round(out["par_value"], 6) + 0.0)
2022-01-03 [0.0078, 0.0137, 0.0163] [0.004, 0.0206, 0.0189] 2023-07-03 [0.0494, 0.0419, 0.0386] [0.0543, 0.0338, 0.0325] 2026-10-09 [0.048, 0.0502, 0.0524] [0.0447, 0.0532, 0.0567] 158400.8 389.98 0.0
- 1The curve, the forwards and one old swap, from real yields.
*Check:* in January 2022 rates were near zero: swap rates of 0.78%, 1.37% and 1.63% for 2, 5 and 10 years. In July 2023 the curve was inverted: 4.94% for 2 years but 3.86% for 10, and the forwards fall from 5.43% in year 1 to 3.25% in year 10, which is the market pricing rate cuts. On 9 October 2026 the curve rises again: 4.80%, 5.02% and 5.24%. A swap struck at 1.37% in 2022 is now worth 158,400.80 to the payer of fixed on one million, with a DV01 of 389.98; a swap struck at today's rate is worth 0. *What to notice:* the swap did not change; the curve did. Everything you computed came from the discount factors, which is why a bank can value ten thousand swaps from one curve.
Between the quoted tenors the lab draws straight lines in par yields. Another interpolation (on zero rates, or on the log of discount factors) gives slightly different forwards, and forwards are sensitive to it. Two banks with the same quotes can value the same swap a few basis points apart because of such choices.
- FunctionQuestion it answers
- interpolate_par(tenors, yields)What is the par rate of every year?fractions, years 1 to N
- bootstrap_discount(par)What does 1 paid in n years cost?every par bond costs 1
- forward_rates(discount)What rate does the curve imply for each year?P_(i-1) / P_i - 1
- annuity(discount, n)What does 1 per year for n years cost?sum of the first n factors
- swap_rate(discount, n)Which fixed rate makes the swap worth nothing?equals the par rate here
- swap_value(discount, K, n, notional, pay_fixed)What is the swap worth to each side?floating minus fixed
- swap_dv01(par, K, n, notional)What does one basis point do?bump, bootstrap, revalue
What you will build
The lab follows the lecture. Task 1 interpolates the par yields to one rate for each year. Task 2 bootstraps the discount factors, the heart of the topic. Tasks 3 to 5 read the forward rates, the annuity and the par swap rate off the factors. Task 6 values a swap for either side and task 7 finds its DV01 by bumping the curve. Task 8 runs everything on the real Treasury file for three days.
Next topic: swaps are a contract on interest. The next one, The forward price and the futures basis, prices a contract to buy an asset later, and shows why a future and a forward on the same thing can differ.
Lab · what's graded
8 tasks · 100 pts- Par rates for every year10 pts
- Bootstrapping the discount factors20 pts
- Forward rates10 pts
- The annuity5 pts
- The par swap rate10 pts
- The value of a swap15 pts
- The DV01 of a swap10 pts
- Three days of the Treasury curve20 pts