A new 10-year Treasury note, bought 45 days after it was issued on 9 October 2026, has a clean price of 99.12 at a yield of 5.24%. The seller is also owed 0.63 of accrued interest, so the buyer pays 99.75. If the yield rose by one point the price would fall by 7.27%; the duration of the bond says 7.61%, and duration with convexity says 7.26%. This topic builds all of these from a coupon, a maturity and a yield.
The cash flows of a bond
Where we are. The last two topics gave you schedules of dates and a way to discount cash flows at one rate. A fixed-rate bond puts them together: it pays a coupon (a fixed share of its face value) at regular dates, and pays back the face value at maturity. The market quotes the face value as 100, so a 5% bond paid twice a year pays 2.5 every six months, and 102.5 on the last date.
The coupon dates are counted backward from the maturity, as in the last topic: the maturity, then six months before, then twelve, and so on. A buyer who settles (takes delivery and pays) on a given day gets only the coupons that come after that day. The coupon dates before it are gone, and the last of them, the previous coupon date, matters for the interest that has built up since.
Worked example 1. *Problem:* list the cash flows of a bond maturing on 15 January 2026 with a 5% coupon paid twice a year, bought on 15 March 2024; then buy it on 15 July 2024, the day of a coupon. *Plan:* use bond_flows. *Steps:* below.
settle, maturity = date(2024, 3, 15), date(2026, 1, 15)previous, flows = bond_flows(settle, maturity, 0.05, 2)1print(previous, [(str(day), amount) for day, amount in flows])previous, flows = bond_flows(date(2024, 7, 15), maturity, 0.05, 2)2print(previous, [(str(day), amount) for day, amount in flows])
2024-01-15 [('2024-07-15', 2.5), ('2025-01-15', 2.5), ('2025-07-15', 2.5), ('2026-01-15', 102.5)]
2024-07-15 [('2025-01-15', 2.5), ('2025-07-15', 2.5), ('2026-01-15', 102.5)]- 1Four cash flows; the last one carries the face value.
- 2On a coupon date that coupon is already paid.
*Check:* bought on 15 March 2024, the previous coupon date is 2024-01-15 and the four flows are 2.5 on 2024-07-15, 2.5 on 2025-01-15, 2.5 on 2025-07-15 and 102.5 on 2026-01-15. Bought on 15 July 2024, the previous coupon date is that same day and only three flows remain, the first on 2025-01-15. *What to notice:* the number of flows depends on the settlement date, and the first flow can be as close as a day or as far as one period.
Dirty, accrued and clean prices
The price of a bond from its yield is the present value of the flows still to come, all discounted at the yield compounded as many times a year as the bond pays. The first flow is less than a full period away, since part of the period has passed. The usual rule, the street convention, measures that part with days: w is the share of the period left until the next coupon date, and the k-th future flow is discounted for w + k periods.
That price is the dirty price: it includes the interest the seller has earned since the previous coupon date, the accrued interest, which grows each day from zero to almost a full coupon. Quoting the dirty price would make the price of a bond jump down each time a coupon is paid, so the market quotes the clean price, the dirty price minus the accrued interest, which does not have that saw-tooth. The buyer pays the clean price plus the accrued interest.
Worked example 2. *Problem:* price the bond of example 1, bought on 15 March 2024, at yields of 4%, 5% and 6% compounded twice a year: the dirty and the clean price. Also find its accrued interest. *Plan:* use dirty_price, accrued_interest and clean_price. *Steps:* below.
settle, maturity = date(2024, 3, 15), date(2026, 1, 15)for yld in (0.04, 0.05, 0.06): print(yld, round(dirty_price(settle, maturity, 0.05, yld, 2), 4), round(clean_price(settle, maturity, 0.05, yld, 2), 4))1print(round(accrued_interest(settle, maturity, 0.05, 2), 4))2
0.04 102.5713 101.7471 0.05 100.8174 99.9932 0.06 99.1025 98.2783 0.8242
- 1Dirty and clean price at three yields.
- 260 days of a 182-day period.
*Check:* the dirty prices are 102.5713, 100.8174 and 99.1025, the clean prices 101.7471, 99.9932 and 98.2783, and the accrued interest is 0.8242, which is 2.5 × 60 / 182: 60 days have passed in a period of 182. *What to notice:* the bond has a 5% coupon and a 5% yield, but its clean price is not exactly 100. It would be exactly 100 on a coupon date; between coupon dates the discounting with a fractional period makes it a little lower.
From a price back to a yield
Traders quote prices, and the yield is what they compare. Finding the yield from a price has no formula for a bond with many coupons, but it can be found by search. The price falls as the yield rises, so there is exactly one yield for each price. Bisection keeps an interval that contains the answer and halves it again and again: look at the middle; if the price there is above the quote, the yield must be higher, so keep the upper half; otherwise keep the lower half. After 200 halvings the interval is so small that the middle is the answer to the last digit.
Worked example 3. *Problem:* find the yield of the bond of example 1 when its clean price is 98.2783, and when it is 101.7471. *Plan:* use bond_yield. *Steps:* below.
settle, maturity = date(2024, 3, 15), date(2026, 1, 15)print(round(bond_yield(98.2783, settle, maturity, 0.05, 2), 6), round(bond_yield(101.7471, settle, maturity, 0.05, 2), 6))1
0.06 0.04
- 1A lower price means a higher yield.
*Check:* the yields are 0.06 and 0.04, the values we used in example 2 to compute those prices. *What to notice:* the same search works for any monotone function, such as the implied volatility of an option, which a later topic finds the same way.
How the price moves: duration and convexity
A risk manager wants to know how much a bond loses if the yield rises by a point. Two numbers answer most of that question. The Macaulay duration is the average time to the cash flows in years, each time weighted by the present value of its cash flow; a bond with no coupons has a duration equal to its maturity, and coupons make it shorter. The modified duration is the Macaulay duration divided by 1 + y / m, and it is the percentage fall of the price for a one-unit rise in the yield.
The price is a curve, not a straight line, as the yield moves. The convexity measures the bend. A bond has positive convexity: when the yield falls the price rises by more than it falls when the yield rises by the same amount. Adding it to the duration gives a second-order estimate of the change of the price.
Worked example 4. *Problem:* find the duration and convexity of 10-year bonds on a coupon date with coupons of 0%, 2%, 5% and 8% at a yield of 5%. Then compare, for the 5% bond, the exact change of the price for yield moves of +1, −1 and +3 points with the estimate from the duration alone and the estimate with convexity. *Plan:* use bond_risk and dirty_price. *Steps:* below.
settle, maturity = date(2024, 7, 15), date(2034, 7, 15)for coupon in (0.0, 0.02, 0.05, 0.08): print(coupon, [round(v, 4) for v in bond_risk(settle, maturity, coupon, 0.05, 2)])1macaulay, modified, convexity = bond_risk(settle, maturity, 0.05, 0.05, 2)2price = dirty_price(settle, maturity, 0.05, 0.05, 2)for move in (0.01, -0.01, 0.03): exact = dirty_price(settle, maturity, 0.05, 0.05 + move, 2) / price - 1 print(move, round(exact, 5), round(-modified * move, 5), round(-modified * move + 0.5 * convexity * move**2, 5))
0.0 [10.0, 9.7561, 99.9405] 0.02 [8.9503, 8.732, 86.2036] 0.05 [7.9894, 7.7946, 73.6287] 0.08 [7.3928, 7.2125, 65.8203] 0.01 -0.07439 -0.07795 -0.07426 -0.01 0.08176 0.07795 0.08163 0.03 -0.20385 -0.23384 -0.2007
- 1Macaulay, modified, convexity.
- 2Longer duration with a lower coupon.
- 3Exact change, duration estimate, duration and convexity.
*Check:* with a 0% coupon the Macaulay duration is 10.0, exactly the maturity; with 2%, 5% and 8% it is 8.9503, 7.9894 and 7.3928. The 5% bond has a modified duration of 7.7946 and a convexity of 73.6287. For a rise of 1 point the price falls by 7.439%: the duration says 7.795% and duration with convexity 7.426%. For a fall of 1 point it rises by 8.176%, against 7.795% and 8.163%. For a rise of 3 points it falls by 20.385%, against 23.384% and 20.070%. *What to notice:* the duration alone overstates the loss and understates the gain, and convexity fixes most of it; for a move of one point the second-order estimate is within 0.02 percentage points of the true change, and for a large move it is only an approximation.
Three new ten-year notes
Worked example 5. *Problem:* price a new 10-year Treasury note on three days, bought 45 days after the issue, with the 10-year yield of the day (compounded twice a year) and a coupon rounded down to a multiple of one eighth of a percent. For each, find the accrued interest, the dirty and clean prices, the yield recovered from the clean price, the duration and convexity, the exact price change for a move of one point up and down, and the two estimates. *Plan:* study combines the functions. *Steps:* below.
out = study(load_data())for day, row in out.items(): print(day, row["coupon"], round(row["accrued"], 4), round(row["clean"], 4), round(row["yield_back"], 6), round(row["modified"], 4), round(row["up"], 5), round(row["estimate"], 5), round(row["estimate2"], 5))1
2007-07-02 0.05 0.6114 99.9943 0.05 7.6753 -0.07329 -0.07675 -0.07317 2020-08-03 0.005 0.0611 99.4241 0.0056 9.6165 -0.0914 -0.09617 -0.09123 2026-10-09 0.05125 0.6336 99.1159 0.0524 7.6134 -0.07271 -0.07613 -0.07259
- 1One row per day.
*Check:* the coupons are 0.05, 0.005 and 0.05125. The accrued interest is 0.6114, 0.0611 and 0.6336, because 45 days of a period are worth a quarter of a coupon: a 5% coupon gives about 0.63 and a coupon of 0.5% only 0.06. The clean prices are 99.9943, 99.4241 and 99.1159, and the yield recovered from them is the original yield (0.05, 0.0056 and 0.0524). The modified duration is 7.6753 in 2007, 9.6165 in 2020 and 7.6134 in 2026; a rise of one point loses 7.329%, 9.140% and 7.271%, while the estimates with convexity give 7.317%, 9.123% and 7.259%. *What to notice:* the low coupon of 2020 makes the bond last longer, which gives the longest duration and the biggest loss; and the convexity estimate is closer to the true value on all three days.
This bond is priced with a single yield for every cash flow, the limit we met in the last topic. Two bonds with the same maturity but different coupons have different cash flow dates and need not have the same yield; a curve would value each cash flow at its own rate, and the topics on curves do that.
- FunctionQuestion it answers
- bond_flows(settle, maturity, coupon, frequency)What will the bond still pay, and when?uses add_monthsQuantLib: FixedRateBond.cashflows
- dirty_price(settle, maturity, coupon, yld, frequency)What does the buyer pay, accrued interest included?uses bond_flowsQuantLib: BondFunctions.dirtyPrice
- accrued_interest(settle, maturity, coupon, frequency)How much interest has the coupon earned?uses bond_flowsQuantLib: Bond.accruedAmount
- clean_price(settle, maturity, coupon, yld, frequency)What is the quoted price?uses the two functions aboveQuantLib: BondFunctions.cleanPrice
- bond_yield(clean, settle, maturity, coupon, frequency)Which yield gives this quote?uses clean_priceQuantLib: BondFunctions.yield
- bond_risk(settle, maturity, coupon, yld, frequency)How much does the price move with the yield?uses dirty_priceQuantLib: BondFunctions.duration
What you will build
The lab follows the lecture. Task 1 builds the cash flows of a bond. Task 2 is the dirty price from a yield, task 3 the accrued interest and task 4 the clean price. Task 5 finds the yield from a price by bisection, and task 6 measures duration and convexity. Task 7 prices three new 10-year Treasury notes at their real yields and tests the estimates of a price change.
Next topic: Vanilla options with analytic engines. The bond is priced by a function that takes the dates, the coupon and the yield as separate arguments; next you write the same kind of function for a call and a put option with the Black-Scholes formula, and its Greeks. You will see that the two pieces of code look alike, and the topic after it asks what the common shape is.
Lab · what's graded
7 tasks · 100 pts- The cash flows14 pts
- The dirty price16 pts
- The accrued interest10 pts
- The clean price6 pts
- The yield from a price16 pts
- Duration and convexity14 pts
- Three new Treasury notes24 pts