Sub topic 11
Solving for the monthly saving target
This chapter combines the required nest egg with compound growth to produce one monthly contribution. It assumes you can do basic algebra, understand compounding, and can read short Python functions. It also assumes you have already estimated spending, inflation, other income and a withdrawal rate. Those inputs appear below as plain numbers.
The problem in one sentence
You know a target balance, a time horizon, an assumed return and what you already have. You want the level monthly payment that closes the gap. Two things grow at once: your existing balance, and each new contribution from the month it is made.
Step 1: Fix the target
The nest egg comes from the first function in the plan. It subtracts other income, inflates the remainder to the retirement date, and divides by the withdrawal rate.
Take a worked example:
- Spending today is 50,000 a year, and a pension and public benefits cover 12,000 of it in today's money.
- Retirement is 30 years away.
- Inflation is 3%, and the withdrawal rate is 4%.
The need in today's money is 38,000. Prices grow by 1.03^30, which is about 2.4273, so the need becomes about 92,236 a year in future dollars. Dividing by 0.04 gives a nest egg of about 2,305,899.
Step 2: Understand what a contribution becomes
Let r be the monthly rate and n the number of months. A payment P made at the end of each month grows as follows:
- The last payment is made at the end, so it has not grown at all and is worth P.
- The one before it has grown for one month and is worth P(1 + r).
- The first payment has grown for n − 1 months and is worth P(1 + r)^(n−1).
Adding these terms gives a geometric series:
FV of payments = P × ((1 + r)^n − 1) / rThe fraction is the annuity factor. It is the future value of one dollar paid per month. At r = 0.5% and n = 360 it is about 1,002.5. Each dollar of monthly saving becomes about 1,002 dollars after 30 years.
Step 3: Credit the existing balance
A balance B you already hold needs no further payments. It only compounds:
FV of balance = B × (1 + r)^nYour final balance is the sum of the two pieces:
Target = B × (1 + r)^n + P × ((1 + r)^n − 1) / rSolve for P:
P = (Target − B × (1 + r)^n) × r / ((1 + r)^n − 1)This is the formula in monthly_saving. The term Target − B × (1 + r)^n is the gap that contributions must fill.
Step 4: The code
The program below includes all three functions from the plan. It also adds a check that the closed form and the simulation agree.
def nest_egg(annual_spend_today, years, inflation, other_income_today=0.0, withdrawal_rate=0.04):
"""Nest egg needed at retirement, in future dollars."""
need_today = max(annual_spend_today - other_income_today, 0.0)
need_future = need_today * (1 + inflation) ** years
return need_future / withdrawal_rate
def monthly_saving(target, years, annual_return, current_balance=0.0):
"""Level monthly contribution, paid at the end of each month, that reaches target."""
n = years * 12
r = annual_return / 12
balance_future = current_balance * (1 + r) ** n
gap = max(target - balance_future, 0.0)
if r == 0:
return gap / n
return gap * r / ((1 + r) ** n - 1)
def simulate(monthly, years, annual_return, balance=0.0, annual_raise=0.0):
"""Month-by-month balance with end-of-month contributions that rise once a year."""
r = annual_return / 12
for month in range(years * 12):
if month > 0 and month % 12 == 0:
monthly *= 1 + annual_raise
balance = balance * (1 + r) + monthly
return balance
target = nest_egg(50_000, 30, 0.03, other_income_today=12_000, withdrawal_rate=0.04)
payment = monthly_saving(target, 30, 0.06, current_balance=40_000)
check = simulate(payment, 30, 0.06, balance=40_000)
print(f"Nest egg: {target:,.0f}")
print(f"Monthly saving: {payment:,.2f}")
print(f"Simulated end: {check:,.0f}")The program prints a nest egg of about 2,305,899 and a monthly saving of about 2,055.61. The simulated ending balance matches the nest egg to within rounding. If it does not, there is a bug in the formula or the inputs.
Step 5: Why the simulation matters
The closed form is fast but opaque. The simulation is slow but transparent. It has no algebra to get wrong, and it also handles cases the formula cannot, such as contributions that rise each year. Use the formula to get an answer and the simulation to confirm it.
With annual_raise=0, the simulation must reproduce the target. With a positive raise, the same starting payment overshoots the target. You can then lower the starting payment until the result matches. Chapter 12 covers that.
Edge cases and gotchas
Zero return
When annual_return is 0, the annuity factor becomes 0/0. The code branches to gap / n, which is simple division of the gap over the months.
Zero years
If years is 0, then n = 0 and the denominator (1 + r)^n − 1 is 0, so the function raises a ZeroDivisionError. A retirement date of today has no time to save. Validate that years is at least 1 before calling.
Balance already exceeds the target
The max(..., 0.0) clamp returns 0 when your grown balance already covers the target. This is correct for the target. Whether you should stop saving is a separate decision, because the result depends on a single return assumption.
Payment timing
The formula assumes the payment is made at the end of each month, which is an ordinary annuity. Payroll deductions usually land during the month, so a payment at the start of the month is closer to reality. For start-of-month payments, divide the result by (1 + r). The difference is about half a percent of the payment at a 6% return. That is small compared with the uncertainty in the return itself.
Monthly rate convention
The code uses annual_return / 12. A 6% annual figure compounded monthly actually yields about 6.17% over a year. If your 6% is an effective annual rate, use (1 + annual_return) ** (1/12) - 1 instead. Pick one convention and keep it throughout.
Matching units
The nest egg is in future dollars, so the return must be nominal, meaning it includes inflation. If you use a real return, the target must stay in today's dollars. Mixing the two is the most common error in this calculation. Here the 6% return and 3% inflation are consistent with the future-dollar target.
The payment is also fixed in nominal dollars. In 30 years, 2,056 a month buys about 41% as much as it does now (1 / 2.4273). That is one reason to raise contributions over time.
A quick sensitivity check
Rerun the example with only the return changed:
| Annual return | Monthly saving (approx.) |
|---|---|
| 5% | 2,556 |
| 6% | 2,056 |
| 7% | 1,624 |
One percentage point of return moves the monthly figure by roughly 20%. The effect is large because 30 years of compounding amplifies small rate differences. The 5% row is a prudent planning case. Chapter 14 tests all the assumptions together.
Summary of the method
- Compute the future-dollar nest egg.
- Grow the existing balance to the retirement date at the same rate you use for contributions.
- Subtract it from the target to get the gap, never below zero.
- Divide the gap by the annuity factor to get the level payment.
- Verify with a simulation.
Exercise
You want a target of 120,000 in 10 years, you start with a balance of 0, and you assume a 0% return. What monthly saving does monthly_saving(120_000, 10, 0.0) return, and why does the function need the r == 0 branch?
Show answer
It returns 1,000 (120,000 divided by 120 months). The branch is needed because with r = 0 the annuity formula divides 0 by 0, which fails. At a zero return, contributions do not grow, so the answer is simply the gap divided by the number of months.
Exercise
Using the chapter's example (target about 2,305,899, 30 years, 6% return), suppose the existing balance rises from 40,000 to 100,000. Without recomputing the payment, would it fall by more or less than 60,000 divided by 360 per month, and why?
Show answer
It falls by more. The extra 60,000 compounds to about 361,355 (60,000 × 6.0226), which is far more than 60,000. The reduction in the gap is therefore about six times larger, so the monthly payment drops by roughly 361,355 × 0.005 / 5.0226, or about 360. That is much more than 60,000 / 360, which is about 167.