Sub topic 8
Projecting how long a portfolio lasts
This chapter builds a deterministic retirement projection in Python and shows how to read its output. It assumes you know compound growth, the nominal and real return distinction from earlier chapters, and how inflation-adjusted withdrawals work. You also need to be able to read short Python functions.
What a deterministic projection is
A deterministic projection uses one fixed set of assumptions: a single return, a single inflation rate and a single spending level. It then steps forward one year at a time. Running it twice gives the same answer, because no randomness is involved.
It answers a narrow question: if the future looked exactly like these assumptions, how many years would this portfolio fund this spending? That makes it a good first sanity check and a poor forecast. Markets do not deliver a constant return, and the chapter on sequence-of-returns risk explained why the order of returns matters. The projection is still worth building, because it shows how sensitive an outcome is to each input.
The yearly loop
Each simulated year has four steps:
- Withdraw the year's spending from the balance.
- Check whether the balance went negative. If it did, the portfolio failed this year, and the answer is the number of years already completed.
- Grow the remaining balance by the nominal return.
- Raise next year's spending by inflation.
The code follows this order exactly:
def years_funded(balance, spending, nominal_return, inflation, max_years=60):
for year in range(1, max_years + 1):
balance -= spending
if balance < 0:
return year - 1
balance *= 1 + nominal_return
spending *= 1 + inflation
return max_years
print(years_funded(1000000, 40000, 0.05, 0.03))With a 1,000,000 portfolio, 40,000 of first-year spending, a 5% nominal return and 3% inflation, this prints 33. A 4% initial withdrawal rate that rises with inflation lasts about 33 years under these assumptions.
Details that affect the answer
- Withdrawal timing. The function withdraws at the start of each year, before growth. This is conservative, because the withdrawn money earns nothing that year. Withdrawing at the end of the year would add a little to the result. Pick one convention and state it.
- Whole years only. The function returns completed years. If the balance cannot cover year 34, it returns 33, not 33.4.
- The cap.
max_years=60stops the loop when a plan never fails, for example when the return is high and spending is low. A result equal tomax_yearsmeans "at least that long", not "exactly that long". - Spending grows from the first year. Year 1 spending is the number you pass in. Inflation first applies to year 2.
Checking the model in real terms
You can run the same projection in today's money. Use the real return from the earlier chapter and hold spending constant:
def real_return(nominal, inflation):
return (1 + nominal) / (1 + inflation) - 1
def years_funded_real(balance, spending, real_ret, max_years=60):
for year in range(1, max_years + 1):
balance -= spending
if balance < 0:
return year - 1
balance *= 1 + real_ret
return max_years
r = real_return(0.05, 0.03)
print(round(r, 4))
print(years_funded_real(1000000, 40000, r))The first line prints 0.0194, and the second prints 33, the same answer as the nominal version. The two versions are mathematically equivalent, because dividing every nominal quantity by the price level turns it into a real one. This gives you two useful checks:
- Exact formula. If you subtracted inflation from the nominal return, you would get 2.0% instead of 1.94%. The error is small each year but compounds over decades.
- Zero-real-return anchor. With a real return of 0%, the portfolio lasts balance divided by spending. For 1,000,000 and 40,000, that is 25 years. Any positive real return should lengthen it. If your result is shorter than 25, something is wrong with the code or the inputs.
The real-terms form is also easier to reason about. The question becomes whether a 1.94% real return can support a 4% real withdrawal for the horizon you care about.
Why the horizon matters as much as the return
The projection returns a number of years, but the retiree needs that number compared with a planning horizon. A result of 33 years looks safe for someone retiring at 65 only if the horizon is below 98. Earlier chapters showed that life expectancy is the wrong horizon, because about half of retirees outlive it. For a couple, the relevant event is that at least one partner is alive. The helper below covers that case, assuming independent lifespans:
def either_survives(p_first, p_second):
return 1 - (1 - p_first) * (1 - p_second)
print(round(either_survives(0.5, 0.4), 2))This prints 0.7. If one person has a 50% chance of reaching a given age and the other a 40% chance, the household has a 70% chance of needing money at that age. The independence assumption is a simplification: partners share health habits, income and often location, so the true figure is somewhat lower.
Use this result when you pick a target. Instead of asking whether the money lasts to life expectancy, ask which age the plan must cover, such as 95 for an individual or 100 for a couple. Then check that years_funded meets that age minus the retirement age.
Seeing how the answer shifts
A single result hides how fragile it is. A short loop makes the sensitivity visible. It uses the years_funded function defined above:
for nominal in (0.03, 0.04, 0.05, 0.06, 0.07):
row = [years_funded(1000000, 40000, nominal, infl) for infl in (0.02, 0.03, 0.04)]
print(nominal, row)Each line prints a nominal return followed by the years funded at 2%, 3% and 4% inflation. Run it and look at three patterns:
- Within a row, higher inflation shortens the result, because spending rises faster than the balance.
- Within a column, higher returns lengthen the result.
- The gap between neighboring cells is uneven. A one-point change in the real return matters far more when the real return is near zero than when it is already high.
The table below shows the effect of each input on the answer:
| Input | Direction of change | Effect on years funded |
|---|---|---|
| Nominal return | Higher | Longer |
| Inflation | Higher | Shorter |
| Starting spending | Higher | Shorter |
| Starting balance | Higher | Longer |
| Withdrawal at end of year | Instead of start | Slightly longer |
The sensitivity grid is the main product of a deterministic model. It shows which assumptions need the most care. The nominal return and inflation combine into one number, the real return, so a pessimistic pair of assumptions has about the same effect as a pessimistic real return.
Common errors
- Using the arithmetic difference for real return.
0.05 - 0.03gives 2.0%, not 1.94%. Use the exact formula. - Mixing nominal and real inputs. Passing a real return to the nominal function, or the reverse, double-counts or ignores inflation. Label variables.
- Forgetting the cap. If the loop returns
max_years, report "at least 60 years", not "60 years". - Treating 33 as a promise. The result is the answer under one path. A bad first decade can shorten it considerably, and the average return can look fine while the plan fails.
- Ignoring other income. Real plans have a public pension or annuity that covers part of spending. Model the withdrawal as spending minus guaranteed income, not total spending.
- Using one inflation rate for all spending. Retiree costs, such as healthcare, may rise faster than the headline rate. A single rate can understate the problem.
Extending the model
The function is deliberately small, and several extensions are straightforward:
- Subtract guaranteed income from spending before withdrawing. Declare it as a parameter, and decide whether it rises with inflation.
- Add fees by subtracting an annual percentage from the nominal return.
- Return the full year-by-year balances instead of only the count, so you can plot the path or inspect when the balance first falls below half of its starting value.
- Pass a list of returns instead of one constant. This turns the function into a replay of a historical or simulated sequence, which is the step toward the next chapter's Monte Carlo approach.
Each extension adds an assumption, so record it next to the result. A projection that lists its assumptions is useful to a reader. One that does not is easy to misread.
What the projection does and does not tell you
A deterministic projection is good at three things: confirming that the arithmetic is correct, showing the effect of each assumption, and giving a rough answer to "is this plan in the right range?" It is weak at representing uncertainty. It gives no probability of success, ignores the order of returns, and treats lifespan as a known number.
The remaining tools address those gaps. Monte Carlo simulation replaces the constant return with many random paths. Annuities and delayed public pension claiming remove part of the longevity uncertainty. Flexible spending rules reduce the withdrawal after bad years. The projection you built here is the engine inside each of them.
Exercise
A retiree has 600,000 and plans to spend 24,000 in year 1, with spending rising by 3% a year. Using the withdraw-then-grow convention in this chapter, assume a nominal return of 3% and inflation of 3%. First, what is the real return? Second, how many years does the portfolio fund?
Show answer
The real return is (1.03 / 1.03) - 1 = 0, so spending is constant in real terms and the portfolio acts like a fixed pot. It funds 600,000 / 24,000 = 25 years. After 25 withdrawals the real balance is exactly zero, which is not below zero, and the 26th withdrawal fails, so years_funded returns 25. (With floating-point arithmetic the result can occasionally differ by one year at an exact boundary like this, which is why you should treat boundary results with caution.)
Exercise
A couple's plan funds 32 years of spending, and they retire at 65. One partner has a 30% chance of reaching 97 and the other a 25% chance. Using the independence assumption, what is the chance that at least one is alive at 97, and what does that imply for the plan?
Show answer
either_survives(0.30, 0.25) = 1 - 0.70 * 0.75 = 0.475, so about a 48% chance that at least one partner is alive at 97. The plan runs out at exactly age 97, so there is close to a coin-flip chance that money is needed after it ends. The couple should extend the funded horizon, reduce spending, add guaranteed income, or plan to adjust spending later.