Sub topic 10
Testing a Rate with Monte Carlo Simulation
This chapter assumes you have read the earlier chapters on real returns, sequence of returns risk, and how a success rate is defined. You should also be comfortable reading short Python functions. The code uses only the standard library.
Why simulate when you can backtest
Historical backtesting replays actual market years. That is honest, but the data is thin. US data gives you roughly one independent 30-year retirement for every 30 years of history. Overlapping start dates (1966, 1967, 1968) share most of their returns, so they are not separate samples.
A Monte Carlo simulation generates many artificial return sequences from a statistical model. You then count how many of them the portfolio survives. The name comes from the casino, because the method relies on random draws.
Monte Carlo lets you ask questions that history cannot answer directly:
- What happens if future returns are lower than the past?
- How does the success rate change with a 40-year horizon instead of 30?
- How sensitive is the result to my assumptions?
It does not create new information about markets. It reshuffles the assumptions you put in. The quality of the answer depends entirely on those assumptions.
The simulation loop
Each trial is one imagined retirement. You draw one real return per year, run the withdrawal logic, and record whether the money lasted. The success rate is the fraction of trials that survived.
The code
The first function tests one path of real returns. The withdrawal is fixed at a percentage of the starting balance and stays constant in real terms. This is the same rule as the 4 percent rule, so inflation is already handled by working in real returns.
import random
def survives(real_returns, withdrawal_rate=0.04, start=1_000_000):
balance = start
withdrawal = start * withdrawal_rate # constant in real terms
for r in real_returns:
balance -= withdrawal
if balance <= 0:
return False
balance *= 1 + r
return True
def success_rate(rate, years=30, mean=0.05, stdev=0.12, trials=10_000, seed=1):
rng = random.Random(seed)
wins = 0
for _ in range(trials):
returns = [rng.gauss(mean, stdev) for _ in range(years)]
if survives(returns, rate):
wins += 1
return wins / trials
for rate in [0.03, 0.035, 0.04, 0.045, 0.05]:
print(f"{rate:.1%} -> {success_rate(rate):.1%}")Several details in this code matter.
- Withdrawal before growth. Each year the withdrawal comes out first and the remainder grows. This is slightly conservative, because spending at the start of the year gives the money less time to grow.
- Failure is hitting zero. The function returns
Falsethe moment the balance cannot cover a withdrawal. This matches the failure definition from the earlier chapter: money runs out before the horizon ends. - Seeded random numbers.
random.Random(seed)creates a private generator. The same seed gives the same paths, so your results are reproducible. - Common random numbers. Every call in the loop uses
seed=1, so each withdrawal rate faces the same 10,000 paths. Differences between rates then reflect the rate, not luck in the draw.
Run it yourself and read your own numbers. The success rate should fall as the rate rises. If it does not, something is wrong.
How accurate is the answer
The estimate is itself noisy. With n trials and a true success probability p, the standard error is sqrt(p * (1 - p) / n). For p = 0.9 and 10,000 trials, that is about 0.003, or 0.3 percentage points. More trials shrink this error, but only slowly: 100 times the trials gives 10 times the precision.
So reporting "91.37%" is false precision. Round to the nearest percent. A difference of 0.2 points between two strategies is below the noise, and a difference of 5 points is not.
This noise is separate from, and usually much smaller than, the error in the assumptions. A simulation can be statistically precise and still wrong about the world.
The inputs that drive the result
Three inputs dominate the output.
| Input | What it represents | Effect of raising it |
|---|---|---|
| `mean` | Average yearly real return | Success rate rises |
| `stdev` | Yearly volatility | Success rate falls, because bad sequences become more likely |
| `years` | Retirement length | Success rate falls |
The mean and stdev values in the code are illustrative. Replace them with your own view of your portfolio.
One subtle point: random.gauss(mean, stdev) draws returns whose arithmetic average is mean. Compounded growth follows the geometric mean, which is lower. A rough approximation is mean - stdev**2 / 2. With a 5% mean and 12% standard deviation, that is about 4.3% per year. Volatility therefore costs you growth even when the average return looks fine. This is the same mechanism behind sequence risk.
You can test how fragile a result is by sweeping the inputs:
for mean in [0.03, 0.04, 0.05]:
for stdev in [0.10, 0.12, 0.15]:
rate = success_rate(0.04, mean=mean, stdev=stdev)
print(f"mean={mean:.0%} stdev={stdev:.0%} -> {rate:.0%}")If the 4 percent rate looks safe at a 5% mean but weak at 3%, you have learned that the conclusion rests on one uncertain number. That is more useful than any single success rate.
What this simple model gets wrong
The model above is deliberately basic. Know its limits before trusting it.
- Independent years. Each draw ignores the previous one. Real markets show valuation effects, such as high starting prices followed by weaker returns, and multi-year bear markets. Independence tends to understate sequence risk.
- Normal distribution. A bell curve underestimates extreme crashes. Real returns have fat tails, so the worst years are worse and more frequent than the model implies.
- A single asset. The model has one return stream. A real portfolio mixes stocks and bonds with a correlation that changes over time, and you rebalance.
- Real returns only. Inflation is folded into the real return. Real inflation shocks, such as the 1970s, hit stocks and bonds together, and a plain model cannot reproduce that.
- Fixed spending. Real retirees cut spending in a crash. The model never does, so it measures the harshest version of the plan. The flexible strategies chapter returns to this.
- No costs or taxes. Fees and taxes reduce what you can spend and are not modeled here.
Better simulators address some of these. They draw from historical blocks of consecutive years (bootstrapping), use fat-tailed distributions, or add regimes for high and low valuations. Each fix adds assumptions of its own.
Reading the result sensibly
Use Monte Carlo to compare options and find fragile points, not to certify a plan.
- Compare rates under identical assumptions, as the sweep above does.
- Run the low-return case along with the base case.
- Look at how fast the success rate falls as the rate rises. A steep drop between 4% and 4.5% warns you that you are near an edge.
- Cross-check against historical backtests. If the two disagree widely, find out why before trusting either.
Many planners treat success rates of around 80 to 95 percent as reasonable when spending can flex. A fixed plan with no ability to cut would warrant a higher target. These thresholds are judgment calls, not rules.
Exercise
You run success_rate(0.04) with mean=0.05 and get 90%. A friend says this means you have a 10% chance of running out of money. Give two reasons the statement overreaches. Then say what you would change in the code to test how much the answer depends on your return assumption.
Show answer
First, the 90% is the share of simulated paths that survived under the chosen mean, standard deviation, independent normal draws, and fixed real spending. It is not a probability about the real world, where returns may be correlated, fat-tailed, or lower than assumed. Second, the model never lets the retiree cut spending, so it describes a rigid plan, and real behavior would change the failure chance. To test the dependence on returns, loop over several mean values (for example 3%, 4%, 5%) and several stdev values, calling success_rate for each, and see how far the result moves. A large swing shows the conclusion rests on a fragile assumption.