Sub topic 12
Testing which assumptions matter most
The model from the previous chapter returns one answer for one set of inputs. Every input is a guess about the future, so that answer is only as good as the guesses. Sensitivity analysis changes the inputs on purpose and watches what happens to the result. It shows which guesses decide the outcome and which barely matter.
This chapter assumes you have the monthly_payment and simulate functions from the model chapter, and that you are comfortable with compound growth and basic Python (loops, dictionaries, keyword arguments).
Why a single answer is not enough
Suppose the model says buying wins after seven years. That tells you little until you know how fragile the result is. If a 1 percentage point change in home appreciation flips it, you have a coin toss. If it holds across every plausible input, you can act on it with more confidence.
Sensitivity analysis answers three questions:
- Which inputs move the result the most?
- How far can each input drift before the best choice changes?
- Which inputs can you actually learn more about, and which are pure forecasts?
The measure: wealth margin
Use one number to compare scenarios: the margin, defined as owner net wealth minus renter portfolio at a chosen horizon. A positive margin means buying leads. A negative margin means renting leads. The size of the margin shows how strongly.
A second useful measure is the break-even year, the first year in which the margin turns positive. Together they show how far the result moves and when the winner changes.
def monthly_payment(principal, annual_rate, years):
r = annual_rate / 12
n = years * 12
if r == 0:
return principal / n
return principal * r / (1 - (1 + r) ** -n)
def simulate(years, price=400_000, down_pct=0.20, mort_rate=0.06, term=30,
appreciation=0.03, invest_return=0.05, rent=2_000,
rent_growth=0.03, carry_rate=0.02, sell_cost=0.06):
loan = price * (1 - down_pct)
pay = monthly_payment(loan, mort_rate, term)
balance = loan
portfolio = price * down_pct # the renter invests the cash the buyer puts down
for m in range(years * 12):
balance -= pay - balance * mort_rate / 12
value = price * (1 + appreciation) ** ((m + 1) / 12)
owner_cost = pay + value * carry_rate / 12 # tax, insurance, maintenance
rent_m = rent * (1 + rent_growth) ** (m // 12)
portfolio = portfolio * (1 + invest_return / 12) + (owner_cost - rent_m)
value = price * (1 + appreciation) ** years
owner_wealth = value * (1 - sell_cost) - balance
return owner_wealth, portfolio
def margin(years, **overrides):
owner, renter = simulate(years, **overrides)
return owner - renter
def breakeven(max_years=30, **overrides):
for y in range(1, max_years + 1):
if margin(y, **overrides) > 0:
return y
return None
print("Margin at 7 years:", round(margin(7)))
print("Break-even year:", breakeven())breakeven returns the first year with a positive margin. It does not check that the margin stays positive afterward. With unusual inputs, such as very low appreciation and a high investment return, the margin can cross zero and cross back. Print the margins for each year when a result looks strange.
One-at-a-time sweeps
The simplest method changes one input at a time while the rest stay at their base values. For each input, pick a low and a high value that you consider plausible, run the model at both, and record the swing in margin. Sorting by swing gives a ranking, often drawn as a "tornado chart" because the largest bar sits at the top.
RANGES = {
"appreciation": (0.00, 0.05),
"invest_return": (0.03, 0.08),
"mort_rate": (0.045, 0.075),
"rent": (1_600, 2_400),
"rent_growth": (0.01, 0.05),
"carry_rate": (0.015, 0.03),
"sell_cost": (0.04, 0.08),
}
def tornado(years, ranges=RANGES):
base = margin(years)
rows = []
for name, (low, high) in ranges.items():
m_low = margin(years, **{name: low})
m_high = margin(years, **{name: high})
rows.append((abs(m_high - m_low), name, m_low, m_high))
rows.sort(reverse=True)
print(f"Horizon {years} years, base margin {base:,.0f}")
for swing, name, m_low, m_high in rows:
print(f"{name:14} low {m_low:>10,.0f} high {m_high:>10,.0f} swing {swing:>10,.0f}")
tornado(7)Run it and read the output in three steps:
- Look at the top rows. These inputs deserve your research time.
- Check the signs. Does any input push the margin across zero between its low and high values? Those are the inputs that can change your decision.
- Compare the bottom rows with the top. Inputs with small swings can stay at rough estimates.
Choosing ranges honestly
The ranking depends on the ranges you feed it. If you give appreciation a range of 0% to 5% and rent growth a range of 2.5% to 3.5%, appreciation will win partly because you assumed more uncertainty about it. Set ranges from evidence:
| Input | Where to find a defensible range |
|---|---|
| `appreciation` | Local price history over 10 to 20 years, including flat or falling periods |
| `invest_return` | Long-run returns of the investment you would really hold, after fees and taxes |
| `mort_rate` | Quotes from several lenders for your credit profile, not the advertised best rate |
| `rent`, `rent_growth` | Listings for comparable homes, and the rent cap rules where you live |
| `carry_rate` | Property tax rate from the local assessor, an insurance quote, and 1% of price per year as a maintenance starting point |
| `sell_cost` | Agent commissions and transfer fees in your market |
Keep the ranges symmetric in plausibility, not in size. A mortgage rate you can quote today has a narrow range. Appreciation over a decade does not.
Horizon is an input too
The time you stay in the home is the most important input for many households, and it behaves differently from the others. Sale costs are paid once, so a short stay spreads them over few years. Early mortgage payments are mostly interest, so a short stay builds little equity. Run the tornado at several horizons and compare:
for y in (3, 7, 15):
print()
tornado(y)Expect the ranking to change with the horizon. At short horizons, sell_cost should matter more, because a fixed percentage of the sale price is taken out of a small amount of accumulated equity. At long horizons, appreciation and invest_return compound over many years and tend to dominate. You can confirm this with your own numbers rather than trusting the general pattern.
Inputs that move together
One-at-a-time sweeps treat inputs as independent, but real inputs are linked. High inflation tends to raise rents, home prices and mortgage rates together. A recession can lower appreciation and investment returns at the same time. Varying one input while holding the others fixed can describe a world that cannot happen.
Test a few coherent scenarios as well:
SCENARIOS = {
"base": {},
"high inflation": {"appreciation": 0.05, "rent_growth": 0.05, "mort_rate": 0.075},
"stagnant market": {"appreciation": 0.00, "rent_growth": 0.01, "invest_return": 0.04},
"boom in stocks": {"invest_return": 0.08, "appreciation": 0.02},
}
for label, overrides in SCENARIOS.items():
print(f"{label:16} margin at 7y: {margin(7, **overrides):>10,.0f} "
f"break-even: {breakeven(**overrides)}")Each scenario is a story about the economy. If buying wins in all of them, or loses in all of them, the choice is robust. If the winner depends on the story, the decision is a bet, and you should weigh it by how much risk you can carry.
Common errors
- Reading the base case as a forecast. The base case is a reference point for comparison. It is not a prediction.
- Using ranges you did not justify. The ranking reflects your ranges. Write down where each one came from.
- Ignoring breakpoints. The most useful output is often the value at which the winner flips, such as "buying wins unless appreciation falls below 1%." Find it by searching between the low and high values.
- Over-reading small differences. If two inputs have similar swings, do not rank them against each other. Treat them as one group of "matters a lot."
- Optimizing for the model. Sweeping until the answer matches what you already wanted is not analysis. Fix your ranges before running the sweep.
Finding a flip point
A short bisection search turns "which input matters" into "how wrong can I be":
def flip_point(name, low, high, years=7, tol=1e-4):
f_low, f_high = margin(years, **{name: low}), margin(years, **{name: high})
if (f_low > 0) == (f_high > 0):
return None # the winner does not change inside this range
while high - low > tol:
mid = (low + high) / 2
if (margin(years, **{name: mid}) > 0) == (f_low > 0):
low = mid
else:
high = mid
return (low + high) / 2
print(flip_point("appreciation", -0.02, 0.06))The function returns None when the sign of the margin is the same at both ends of the range. Otherwise it returns the value where the margin changes sign. Compare that value with your belief: if the flip point is an appreciation rate you consider unlikely, the decision is safe on that input.
Exercise
A tornado sweep at a 5-year horizon shows that sell_cost has a swing of 30,000 and rent_growth has a swing of 8,000. Can you conclude that selling costs matter more than rent growth for your decision? What would you check first?
Show answer
Not yet. The swings depend on the ranges you chose. Check whether the sellcost range (for example 4% to 8%) is as plausible as the rentgrowth range. Then check whether either input moves the margin across zero, since an input with a large swing that never changes the winner matters less than a smaller one that does. Finally, re-run at your realistic horizon, because the ranking changes with the number of years.
Exercise
Write a call that prints the break-even year when appreciation is 1% and the investment return is 7% at the same time. Why is this test more informative than varying each input alone?
Show answer
print(breakeven(appreciation=0.01, invest_return=0.07)). It tests a joint scenario that is bad for buying on both sides. One-at-a-time sweeps can miss cases where two unfavorable inputs combine, and the result shows whether the decision survives a pessimistic but coherent story.