Cash flows on a timeline
An annuity pays the same amount once a period for periods. On a desk the first question is when each payment arrives.
A loan repayment, a bond coupon or a pension payment usually comes at the end of each period. So the first one is a full period away.
Each payment is discounted back to today, as in case study 0.2.4: a payment at time is worth now. Here is the rate per period, compounded once per period, and counts periods.
Each arrow is a payment; the number under it is its present value. Moving every payment one period earlier, from the end of the year to the start, raises the total from 993.64 to 1,073.13.
Rate and period must match. A rate quoted as 6% a year and paid monthly means per month, over months (case study 1.4.6). Mixing a yearly rate with monthly payments is the most common error on a desk.
An annuity is a geometric series
Add the present values of the payments:
Write , the value today of $1 paid in one period. Each term is the one before times , so this is a geometric series (lesson 1.5.2) with first term , ratio and terms.
Its sum is . Since , the front part is just , and .
Rule: Present value of an annuity
is the payment each period, the rate per period and the number of payments, the first one period from now. The fraction is the annuity factor: the value today of $1 a period for periods.
Try it
The machine from case study 0.2.4 saves $300 a year for 4 years. At 8% the four savings are worth 277.78, 257.20, 238.15 and 220.51 today, the numbers on the timeline.
Their sum and the formula agree: $993.64, apart from rounding in the last digits.
When the rate is zero
At the formula reads : the ratio is exactly 1, the case lesson 1.5.2 warned about. Nothing is discounted, so the value is simply . Twelve payments of $100 at 0% are worth $1,200.
Zero and even slightly negative rates do happen, so pricing code needs a branch for . A negative rate above still works in the formula: is then above 1, so each payment is worth more today than its amount.
Payments at the start: the annuity due
Rent, leases and insurance premiums are usually paid in advance, at the start of each period. A stream whose first payment is today is an annuity due.
Every payment arrives one period earlier than in the ordinary annuity, so each is worth times as much. The total is too.
Rule: Annuity due
The ordinary annuity times one extra period of growth. On the timeline, the machine's savings rise from $993.64 to $1,073.13 when they arrive at the start of each year.
Try it
annuity handles both timings and the zero rate. The middle line is the machine both ways.
The last line is a year of rent, $2,000 a month at 0.5% a month. Paid at the end of each month it is worth $23,237.86; paid in advance, $23,354.05.
In code, the two timings differ only in where the sum starts. The end of each period is range(1, n + 1); the start is range(0, n). An off-by-one there is a real pricing error, not a rounding one.
Perpetuities: the annuity that never stops
A perpetuity pays every period for ever. Its value is the limit of the annuity as grows. When , the ratio is below 1, so (lesson 1.5.1) and the infinite geometric series of lesson 1.5.3 converges.
Rule: Perpetuity
The annuity formula with gone. $5 a year for ever at 4% is worth today: far-off payments are worth almost nothing, so an endless stream has a finite price.
| years of payments | 10 | 30 | 100 | 500 | for ever |
|---|---|---|---|---|---|
| value of $5 a year at 4% | 40.55 | 86.46 | 122.52 | 125.00 | 125 |
How many years does it take to get within 1% of the perpetuity? The annuity is times , so it falls short by the fraction . Solve as in lesson 1.5.3: , so 118 years.
Turning this round explains the annuity formula. An -period annuity is a perpetuity starting now minus one whose first payment is in period .
The second is worth at time , so today. For $5 at 4% over 10 years, .
A growing perpetuity, and when it breaks
If the payment grows by a fraction each period, the terms are : a geometric series with ratio . It converges only when that ratio is below 1, that is when .
Rule: Growing perpetuity
is the first payment, one period from now. $5 growing 2% a year at 6% is worth .
When the series diverges, exactly as lesson 1.5.3 found for a ratio of 1 or more. The formula does not warn you: with it returns , a negative price for positive payments.
Analysts using this formula to value shares check first. For the same reason, a level perpetuity has no finite value at a zero or negative rate.
Try it
The first loop rebuilds the table. The next lines give the 117.4 years and the annuity as the difference of two perpetuities.
The last line prints the growing-perpetuity formula and a direct sum over 5,000 years, both 125, then the formula with .
Bond prices
A bond pays a coupon (in dollars, once a year) and repays its face value after years. So it is an annuity of coupons plus one final payment. Case study 1.3.5 added the payments one by one; the annuity factor does the coupons in one step.
Discount both at the bond's yield :
The 5-year 4% bond pays $4 a year on $100 of face value. At a 5% yield its coupons are worth 17.32 and its face value 78.35, so its price is 95.67, as in case study 1.3.5. Prices are quoted per 100 of face value.
At, above and below par
The coupon rate is , here 4%. When the yield equals the coupon rate, , so the coupon part is . Adding the face part leaves exactly : the bond is priced at par, whatever its maturity.
Rule: Par, premium and discount
A bond paying more than the market's yield is worth more than its face value, and the reverse. The yield that prices a bond at par is its par yield; case study 1.6.4 builds a curve from them.
| yield | 0% | 2% | 3% | 4% | 5% | 6% |
|---|---|---|---|---|---|---|
| 5-year 4% bond | 120.00 | 109.43 | 104.58 | 100.00 | 95.67 | 91.58 |
At a 0% yield nothing is discounted, so the price is the plain total of the payments, . That is the zero-rate branch again.
Every 4% bond is at par when the yield is 4%. Below that yield it trades at a premium, above it at a discount, and the longer bond swings further both ways.
The curve falls as the yield rises, and it bends upwards. Case study 2.2.4 measures how fast it falls, the bond's duration, using this formula.
Two desk conventions
Pull to par. As a bond nears maturity its price moves towards face value. At a 5% yield the 4% bond is worth 92.28 with 10 years left, 95.67 with 5, 98.14 with 2 and 99.05 with 1. At maturity it repays exactly 100, with its last coupon.
Semi-annual coupons. Many government and corporate bonds pay half the coupon every six months. Then the coupon is , the rate per period is and there are periods. The 5-year 4% bond at a 5% yield, priced this way, is worth 95.62 instead of 95.67.
Try it
bond_price is the annuity of coupons plus the discounted face value, with the zero-yield branch. The first loop rebuilds the table, rounded to cents.
Then come the payment-by-payment sum at 5%, the pull to par, and the semi-annual price: coupon 2, rate 2.5% and 10 periods.
Solving for the payment
A loan is an annuity seen from the lender's side: the amount lent is the present value of the payments. Rearrange the annuity formula for (lesson 0.3.2).
Rule: Loan payment
For the mortgage, , the monthly rate is and there are payments. At the payment is just : $12,000 over 24 months is $500 a month.
Each payment first covers the month's interest on what is still owed; the rest repays the loan. The balance at any time is the present value of the payments still to come. After 10 years, 240 payments remain, worth $251,057.17: about 84% of the loan is still owed after a third of the term.
Try it
The payment is $1,798.65 a month. Times 360 that is $647,514.57, of which $347,514.57 is interest.
The first payment is $1,500.00 of interest and only $298.65 of repayment. The last line is the balance after 10 years and its share of the loan.
Annuities, loans and bonds
Write three functions. Rates are per period, as decimals.
annuity_pv(payment, rate, periods, due=False)returns the present value ofperiodsequal payments. Withdue=Truethe first payment is today. Handlerate == 0.loan_payment(principal, rate, periods)returns the payment that repaysprincipal, also at a zero rate.bond_price(coupon, face, years, y)returns the price of a bond with yearly coupons at yieldy, using the annuity formula.
The tests check each one against a direct sum, at par, above and below it, and at a zero rate.
See the tests
def test_annuity_matches_sum():
"""$300 a year for 4 years at 8% matches the direct sum, about $993.64"""
direct = sum(300 / 1.08**t for t in range(1, 5))
expect_close(annuity_pv(300, 0.08, 4), direct, what="annuity_pv(300, 0.08, 4)")
def test_annuity_due():
"""Paid at the start of each year instead, the same $300 is worth about $1,073.13"""
direct = sum(300 / 1.08**t for t in range(0, 4))
expect_close(annuity_pv(300, 0.08, 4, due=True), direct, what="annuity_pv(300, 0.08, 4, due=True)")
def test_annuity_zero_rate():
"""At a 0% rate, 12 payments of $100 are worth $1,200"""
expect_close(annuity_pv(100, 0, 12), 1200.0, what="annuity_pv(100, 0, 12)")
def test_long_annuity_near_perpetuity():
"""$5 a year for 500 years at 4% is within a cent of the perpetuity, $125"""
expect_close(annuity_pv(5, 0.04, 500), 125.0, what="annuity_pv(5, 0.04, 500)", abs_tol=0.01, rel=0)
def test_mortgage_payment():
"""A $300,000 loan at 0.5% a month for 360 months costs about $1,798.65 a month"""
expect_close(loan_payment(300_000, 0.005, 360), 1798.6515754582708, what="loan_payment(300000, 0.005, 360)")
def test_payment_repays_loan():
"""The payments' present value equals the amount borrowed"""
pay = loan_payment(20_000, 0.004, 60)
expect_close(sum(pay / 1.004**t for t in range(1, 61)), 20_000, what="present value of your payments")
def test_loan_zero_rate():
"""At a 0% rate, $12,000 over 24 months costs $500 a month"""
expect_close(loan_payment(12_000, 0, 24), 500.0, what="loan_payment(12000, 0, 24)")
def test_bond_at_par():
"""A 4% bond at a 4% yield is priced at its face value, 100"""
expect_close(bond_price(4, 100, 5, 0.04), 100.0, what="bond_price(4, 100, 5, 0.04)")
def test_bond_matches_sum():
"""The 5-year 4% bond at 5% matches the payment-by-payment sum, about 95.67"""
direct = sum(4 / 1.05**t for t in range(1, 6)) + 100 / 1.05**5
expect_close(bond_price(4, 100, 5, 0.05), direct, what="bond_price(4, 100, 5, 0.05)")
def test_bond_premium():
"""At a 3% yield the same bond trades above par, at about 104.58"""
direct = sum(4 / 1.03**t for t in range(1, 6)) + 100 / 1.03**5
expect_close(bond_price(4, 100, 5, 0.03), direct, what="bond_price(4, 100, 5, 0.03)")
def test_bond_zero_yield():
"""At a 0% yield the price is the plain total of the payments, 120"""
expect_close(bond_price(4, 100, 5, 0), 120.0, what="bond_price(4, 100, 5, 0)")
Summary card
- An annuity is a geometric series with ratio : , first payment one period away, rate and count per period. At , .
- An annuity due (first payment today) is worth times as much.
- A perpetuity is the limit as : for . Growing at : , only when .
- A bond is an annuity of coupons plus the discounted face value. Yield below the coupon rate: premium; equal: par; above: discount.
- A loan payment rearranges the annuity formula: . The balance is the value of the payments still to come.