Sub topic 13
Sensitivity Analysis on the Structured Model
Sensitivity analysis measures how much an output changes when you change one or more inputs. This chapter assumes you have read the earlier chapters on the three layers. It also assumes you are comfortable with absolute references in a spreadsheet and with basic Python functions and dictionaries.
Why the structure makes sensitivity cheap
A sensitivity run has three steps: pick an input, change it, and read an output. In a model with separate layers, each step has exactly one place to go:
- Every assumption is in the inputs layer, so you know where to change it.
- Every formula reads from the inputs layer and holds no constants, so the change reaches every calculation that depends on it.
- Every result is in the outputs layer, so you know where to read it.
A model with hardcodes in formulas breaks this. If a growth rate of 10% is typed into three formulas, changing the input cell moves only some of the model, and the sensitivity table is wrong without any visible error.
The sensitivity tool should sit on top of the model. It may change inputs and read outputs. It must not add logic to the calculations layer.
Choosing what to flex
Decide three things before building anything.
- The output metric. Use one clear number, such as year-3 net income, NPV, or ending cash. A table that reports ten metrics at once is hard to read.
- The inputs to flex. Start with every numeric input that is uncertain. Skip structural inputs such as the number of years.
- The size of the shock. Either a relative shock (±10% of the base value) or a realistic range (growth from 5% to 15%). Relative shocks are comparable across inputs. Realistic ranges are more honest, because a 10% change in a tax rate is rarely the risk you face.
Three standard outputs cover most needs:
| Type | Varies | Answers |
|---|---|---|
| One-way table | One input over a list of values | How does the metric respond to this input? |
| Tornado | Every input, one at a time, by the same relative shock | Which input matters most? |
| Two-way grid | Two inputs over two lists | How do two assumptions interact? |
A sensitivity runner in code
The code below reuses the model from the architecture chapter. The runner never edits inputs. It copies the dictionary, overrides one or two keys, and calls the same calculate function. That keeps the base case safe and guarantees the sensitivity uses the real model logic.
inputs = {
"revenue_year1": 1_000_000, # currency units
"growth_rate": 0.10, # fraction per year
"cogs_pct": 0.60, # fraction of revenue
"opex": 150_000, # currency units per year
"tax_rate": 0.25, # fraction of positive EBIT
"years": 3,
}
def calculate(inp):
rows = []
revenue = inp["revenue_year1"]
for year in range(1, inp["years"] + 1):
if year > 1:
revenue = revenue * (1 + inp["growth_rate"])
gross_profit = revenue * (1 - inp["cogs_pct"])
ebit = gross_profit - inp["opex"]
tax = max(ebit, 0) * inp["tax_rate"]
rows.append({"year": year, "revenue": revenue,
"ebit": ebit, "net_income": ebit - tax})
return rows
def final_net_income(inp):
return calculate(inp)[-1]["net_income"]
def two_way(inp, key_a, values_a, key_b, values_b, metric):
grid = []
for a in values_a:
row = []
for b in values_b:
trial = dict(inp)
trial[key_a] = a
trial[key_b] = b
row.append(metric(trial))
grid.append(row)
return grid
def tornado(inp, keys, metric, shock=0.10):
base = metric(inp)
rows = []
for key in keys:
low = dict(inp)
low[key] = inp[key] * (1 - shock)
high = dict(inp)
high[key] = inp[key] * (1 + shock)
rows.append((key, metric(low) - base, metric(high) - base))
rows.sort(key=lambda r: max(abs(r[1]), abs(r[2])), reverse=True)
return rows
print(f"Base year-3 net income: {final_net_income(inputs):,.0f}")
keys = ["revenue_year1", "growth_rate", "cogs_pct", "opex", "tax_rate"]
for key, d_low, d_high in tornado(inputs, keys, final_net_income):
print(f"{key:14s} -10%: {d_low:>10,.0f} +10%: {d_high:>10,.0f}")
growth_values = [0.05, 0.10, 0.15]
cogs_values = [0.55, 0.60, 0.65]
grid = two_way(inputs, "growth_rate", growth_values,
"cogs_pct", cogs_values, final_net_income)
print("growth \\ cogs " + "".join(f"{c:>10.0%}" for c in cogs_values))
for g, row in zip(growth_values, grid):
print(f"{g:>13.0%} " + "".join(f"{v:>10,.0f}" for v in row))The base year-3 net income is 250,500. The tornado shocks each input by 10% of its own value and reports the change in that number.
| Input | Net income at -10% | Net income at +10% | Swing |
|---|---|---|---|
| `cogs_pct` | 304,950 | 196,050 | 108,900 |
| `revenue_year1` | 214,200 | 286,800 | 72,600 |
| `opex` | 261,750 | 239,250 | 22,500 |
| `tax_rate` | 258,850 | 242,150 | 16,700 |
| `growth_rate` | 243,930 | 257,130 | 13,200 |
The cost of goods ratio dominates, so it deserves the most careful sourcing. The growth rate looks unimportant, but only because a 10% relative shock moves it from 10% to 11%. A shock of five percentage points would tell a different story. This is why you should check the shock size against the real uncertainty.
Sensitivity in a spreadsheet
Excel's Data Table feature (What-If Analysis) does the same job. It reruns the whole model for each combination of values and records one output cell. It has one restriction that affects structure: the row and column input cells must be on the same sheet as the table.
The usual solution keeps the model unchanged and adds a shift cell for each input you want to flex:
Inputs!C5 = 0.10 (base growth rate, blue input cell)
Inputs!C30 = 0 (growth shift for sensitivity, always 0 in the base case)
Inputs!D5 = C5 + C30 (live growth rate, the only growth cell Calc reads)
Calc!E10 = D10*(1+Inputs!$D$5) (revenue, same formula across every year column)
Checks!C11 = IF(Inputs!C30=0, 0, 1) (fails if a shift was left switched on)Place the Data Table on the Inputs sheet, or place the shift cells on the sensitivity sheet and point Inputs!D5 at them. Either way, the table's corner cell links to a single output, such as =Outputs!C8.
This design has two consequences:
- Calculations read the live cell (
D5), never the base cell (C5). If one formula reads the base cell, the sensitivity skips it. - The shift cell must be zero in the base case. A check that tests this belongs in the integrity checks layer.
Edge cases and failure modes
- Stale tables. Data Tables recalculate with the whole workbook, which slows large models. Setting calculation to "Automatic except for data tables" is common. The risk is presenting a table that is out of date. Recalculate with F9 before you copy results.
- Hardcodes and sensitivity. A hardcoded constant in a formula is invisible to a sensitivity run. If the tornado shows an input with zero swing, the input is either irrelevant or bypassed by a hardcode. Investigate which.
- Dependent inputs. Some inputs move together, for example price and volume. Flexing one while holding the other fixed can describe a situation that can never happen. Use a scenario switch to move related inputs together, then run the sensitivity on the scenario output.
- Non-linear metrics. Taxes with a floor (
max(ebit, 0)), debt covenants and cash sweeps all create kinks. A ±10% shock can sit entirely on one side of a kink and hide the risk. Use wide ranges and read the one-way table, not just the tornado. - Mutating the base. In code, assigning
inp[key] = valueon the original dictionary changes the base case for every later run. Always copy first, asdict(inp)does above. If inputs contain nested dictionaries, usecopy.deepcopy. - Reading a result from the wrong layer. The metric should come from the outputs layer. If you read an intermediate calculation row instead, your sensitivity can drift away from the figure management sees.
Practice
Exercise
In the tornado table, growth_rate has the smallest swing. A colleague concludes that growth does not matter for year-3 net income. Give two reasons the conclusion may be wrong.
Show answer
First, the shock is relative, so growth moved only from 10% to 11% and 9%, a much narrower range than the real uncertainty in growth. A shock of several percentage points would produce a bigger swing. Second, the swing is measured for year-3 net income only. Growth compounds, so its effect would be larger for a longer horizon or for a metric such as the terminal value. The conclusion needs a realistic range and the right metric before it can be trusted.
Exercise
In a spreadsheet, a one-way Data Table on Inputs!C5 shows the same output value in every row. List the likely causes and how you would find them.
Show answer
Likely causes are that the calculation formulas read a different cell than the one the table varies (for example a hardcoded 0.10 or a copy of the input on another sheet), that calculation is set to "Automatic except for data tables" and has not been recalculated, or that the table's input cell reference points at the wrong cell. Use Trace Dependents on the input cell to confirm it feeds the calculation, search the calculation sheet for typed constants, and press F9 to force a recalculation.