---
title: "Spending to the Frontier: the Model"
subtitle: "The synthetic firm, its loss model, the control levers and the simulator checks"
---
```{r setup}
#| include: false
source("R/_setup.R")
res <- load_all()
cal <- res$calibration
ver <- res$verification
app <- appetite_value(reg, cfg, cal$tvar)
sc_names <- unlist(cfg$scenarios)
```
All values are illustrative. The firm is synthetic; every input comes from the assumptions register in `data/assumptions_register.csv`.
## The firm and its four loss scenarios
The study models a synthetic US financial services firm with `r fmt_value(param(reg, "ORG_REVENUE"), "USD")` of annual revenue and `r format(param(reg, "ORG_EMPLOYEES"), big.mark = ",")` employees. The board has approved `r fmt_m(param(reg, "BUDGET_TOTAL"), 1)` a year of new control spend, with no single control taking more than `r fmt_pct(param(reg, "BUDGET_MAX_SHARE"))` of it. Losses come from four scenarios: `r paste(tolower(sc_names), collapse = "; ")`.
## The assumptions register
Every number the model uses is a row in the assumptions register, and each row carries an evidence grade. Strong and moderate rows rest on peer-reviewed or large-sample sources; weak rows on thin or indirect evidence; expert rows on judgment; gap rows on nothing better than a placeholder; design rows are choices about the synthetic firm.
```{r}
#| label: tbl-grades
#| tbl-cap: "Register rows by block and evidence grade."
grade_summary(reg)
```
```{r}
#| include: false
gs <- table(factor(reg$evidence_grade, levels = grade_levels))
n_ce <- sum(reg$block == "control_effect")
n_ce_weak <- sum(reg$block == "control_effect" & reg$evidence_grade %in% c("weak", "expert", "gap"))
```
**How to read the table.** Each row is one block of the register, such as loss frequency, loss severity or control effects. Each column counts the inputs in that block with a given evidence grade, from strong (peer-reviewed, large samples) to gap (no usable evidence) and design (a choice about the synthetic firm). The Total column gives the block's size. The register holds `r nrow(reg)` rows in all, and only `r gs[["strong"]]` of them are graded strong.
**What the table tells you.** Evidence is thinnest where the decision is made. Of the `r n_ce` control-effect rows, `r n_ce_weak` are graded weak, expert or gap, and every frequency row is graded weak because no source matches this firm's size and sector. The optimizer can only redistribute the budget according to these inputs, so the recommendation inherits their uncertainty. The [Robustness](robustness.qmd) page re-runs the search under `r cfg$robustness$n_effect_draws` random draws of them.
::: {.callout-note collapse="true" icon="false"}
## Full assumptions register (`r nrow(reg)` rows)
```{r}
#| label: tbl-register
#| tbl-cap: "The assumptions register: base value, range, evidence grade, sources and status for every model input."
register_table(reg, unique(reg$block))
```
**How to read the table.** Each row is one model input. Base is the value used in the main results; Range is the low-to-high span used in the robustness draws. Applies lists the scenarios the input affects. Evidence gives its grade and Sources its citations. Status marks whether the input enters the main model (active), only the identity sensitivity case (candidate) or nothing (excluded).
**What the table tells you.** This table is the single source of truth: no number on the site is typed by hand. After an external review, the ransomware under-reporting factor was set to 1, because the base rate is insurance-based. Frequency rows were regraded weak, and the breach median moved to current dollars. Phishing training is listed but excluded, so it never enters the search; the rationale column shows how its effect size was derived.
:::
## How often incidents happen
```{r}
#| label: tbl-frequency
#| tbl-cap: "Expected annual events by scenario: base rate, its basis, the under-reporting factor and the effective rate used in the model."
fr_rows <- reg[grepl("^FREQ_", reg$param_id), ]
s_codes <- sub("^FREQ_", "", fr_rows$param_id)
d <- data.frame(Scenario = sc_names[s_codes], base = fr_rows$base, basis = fr_rows$freq_basis,
factor = vapply(s_codes, function(s) param(reg, paste0("UNDERREPORT_", s)), 0),
grade = fr_rows$evidence_grade)
d$effective <- d$base * d$factor
gt_house(d[, c("Scenario", "base", "basis", "factor", "effective", "grade")]) |>
gt::fmt_number(c(base, effective), decimals = 3) |>
gt::fmt_number(factor, decimals = 2) |>
gt::cols_label(base = "Base rate (events a year)", basis = "Basis of the rate", factor = "Under-reporting factor",
effective = "Effective rate", grade = "Evidence grade")
```
**How to read the table.** Each row is one loss scenario. The base rate is the expected number of incidents a year from the register, and the basis says what kind of data it came from. An under-reporting factor corrects counts of publicly disclosed incidents for incidents never disclosed. The effective rate, base rate times factor, is what the simulator uses. The register's validator stops the model if an insurance-based rate carries a factor other than 1.
**What the table tells you.** All four rates are insurance-based, so every factor is 1 and the effective rates equal the base rates. An earlier version multiplied the ransomware rate alone by 5.29, a correction meant for public-disclosure counts. That inflated ransomware's share of expected loss and drove the allocation toward ransomware controls. With it removed, the firm expects `r sprintf("%.3f", sum(d$effective))` incidents a year across all four scenarios.
## The loss model
Each simulated year draws a number of events for each scenario and a loss for each event, then adds them up. Every candidate allocation is scored on the same `r safe(format(cal$n_years, big.mark = ","))` simulated years.
- **How often.** Event counts follow a negative binomial distribution with the effective rate as the mean and dispersion `r param(reg, "NB_SIZE")`, so repeat incidents in a year are common.
- **How large.** Each event's loss follows a lognormal body up to its `r fmt_pct(param(reg, "TAIL_SPLICE_Q"))` quantile, joined to a generalized Pareto tail. The tail is matched to the body's mean excess at the join, the average amount by which losses above it exceed it. Its shape is the larger of the register value (`r param(reg, "TAIL_XI")`) and the body's local mean-excess slope, and its scale is raised further if needed so the tail never sits below the plain lognormal. Data-breach losses are converted to current dollars (factor `r sprintf("%.3f", param(reg, "CPI_ADJ_DB"))`, from 2015 to 2025 consumer prices). No single event can exceed `r fmt_value(param(reg, "EVENT_CAP"), "USD")`.
- **Same years for every allocation.** All allocations are scored on the same simulated years (common random numbers), with a separate random stream for each scenario. A cheaper allocation can never look better just because it drew a quieter set of years.
- **Common shock, off in the base case.** A ransomware event can also cause a data breach with probability `r param(reg, "DEP_RAN_DB")`. A stress test on the Robustness page raises this to `r cfg$robustness$dep_stress`.
- **Expected loss without simulation.** Expected annual loss also has a closed form: frequency times frequency multiplier times expected capped severity. It agrees with the simulation (`r safe(fmt_m(cal$ale_analytic, 3))` against `r safe(fmt_m(cal$ale, 3))` at zero spend) and lets the study find the exact expected-loss optimum.
The board's tail measure is **TVaR95**: the average loss in the worst 1-in-20 years. It looks inside the bad years rather than at a single cut-off, so it reflects how bad the bad years are, not just how often they happen.
```{r}
#| label: tbl-calibration
#| tbl-cap: "Zero-spend calibration by scenario: frequency, severity inputs, tail shape and contribution to the expected annual loss."
#| results: asis
if (is.null(cal)) missing_result("calibration") else {
sp <- severity_params(reg, cfg)
d <- data.frame(Scenario = sc_names, freq = cal$freq, median = sp$median / 1e6, sigma = sp$sigma,
xi = cal$tails$xi, ale = cal$by_scenario / 1e6, share = cal$by_scenario / sum(cal$by_scenario))
d <- rbind(d, data.frame(Scenario = "All scenarios", freq = sum(cal$freq), median = NA, sigma = NA, xi = NA,
ale = cal$ale / 1e6, share = 1))
gt_house(d) |>
gt::fmt_number(freq, decimals = 3) |>
gt::fmt_currency(c(median, ale), decimals = 3, pattern = "{x}M") |>
gt::fmt_number(c(sigma, xi), decimals = 2) |>
gt::fmt_percent(share, decimals = 0) |>
gt::sub_missing(missing_text = "") |>
gt::cols_label(freq = "Events a year", median = "Median event loss", sigma = "Lognormal sigma",
xi = "Tail shape used", ale = "Expected annual loss", share = "Share of loss") |>
gt::tab_style(gt::cell_text(weight = "bold"), gt::cells_body(rows = Scenario == "All scenarios"))
}
```
**How to read the table.** Each row is one loss scenario before any new spending. Events a year is the expected number of incidents; Median event loss is the typical size of one. Lognormal sigma sets how widely losses spread, and Tail shape used sets how heavy the extreme tail is: higher means fatter. Expected annual loss is the long-run average cost a year, and the last column is each scenario's share of it.
**What the table tells you.** With no new spending the firm expects to lose `r safe(fmt_m(cal$ale, 2))` a year. Ransomware supplies `r safe(fmt_pct(cal$by_scenario[["RAN"]] / cal$ale))` of it, no longer the overwhelming share it had before the frequency correction. In the worst 1-in-20 years the average loss is `r safe(fmt_m(cal$tvar, 1))`, `r safe(if (cal$gate) "above" else "below")` the board's `r fmt_m(app, 0)` appetite. A loss occurs in only `r safe(fmt_pct(cal$share_loss_years))` of years, so the bad years drive the risk.
```{r}
#| label: fig-baseline-lec
#| fig-cap: "Loss-exceedance curve: the chance that total annual loss exceeds each amount, with no new spending and with the recommended allocation."
#| fig-alt: "A log-log chart of annual loss against the chance of exceeding it. Two falling curves; the recommended allocation's curve sits below the no-spend curve across the range of large losses."
#| fig-height: 5.2
#| results: asis
if (is.null(cal)) missing_result("calibration") else plot_lec(cal$lec, res$finalists$lec)
```
```{r}
#| include: false
lec_at <- function(lec, x) safe(lec$exceed[which.min(abs(lec$loss - x))])
```
**How to read the plot.** The horizontal axis is a total annual loss and the vertical axis is the chance of losing more than that in a year. Both use log scales, so each step is a factor of ten. The amber curve is the firm with no new spending and the navy curve is the firm with the recommended allocation. The dashed line marks a 1-in-20 chance, the threshold behind TVaR95.
**What the plot tells you.** With no new spending, the chance of losing more than $10M in a year is `r safe(fmt_pct(lec_at(cal$lec, 1e7), 2))`. With the recommended allocation it falls to `r safe(fmt_pct(lec_at(res$finalists$lec, 1e7), 2))`. The curves start together because small annual losses are common either way. The gap opens in the tail, where the controls remove large incidents. The curves cross the 1-in-20 line far below the losses that drive TVaR95.
## The control levers
Each lever reduces how often incidents happen, how much they cost, or both, with diminishing returns. A lever's added reduction at spend $x$ is
$$r(x) = m\,(1 - b)\,\frac{x}{x + k_{50}},$$
where $m$ is its maximum achievable reduction, $b$ the share of that maximum already in place and $k_{50}$ the spend that closes half of the remaining gap. Reductions on the same scenario multiply. Two pairs overlap: hardening and patching both close exploitable exposure, and EDR and logging both shorten dwell time. For an overlapping pair with reductions $r_A$ and $r_B$ and overlap weight $w$, the combined reduction is
$$r_{AB} = (1 - w)\,\bigl(1 - (1 - r_A)(1 - r_B)\bigr) + w\,\max(r_A, r_B),$$
which treats the two levers the same way whichever is funded first. The weights are `r param(reg, "OVERLAP_HARD_PATCH")` for hardening and patching (frequency) and `r param(reg, "OVERLAP_EDR_LOG")` for EDR and logging (severity).
```{r}
#| label: fig-response-curves
#| fig-cap: "Response curves: added reduction in each lever's main effect as its spend rises, from the register's base values."
#| fig-alt: "Seven rising, flattening curves, one per lever, showing the added reduction from 0 to 2 million dollars of spend. Identity, hardening and patching rise fastest; resilience and logging rise least in their main effect."
#| fig-height: 5.4
plot_response_curves(reg, cfg)
```
```{r}
#| include: false
rc_at <- function(lv, x = 1e6) {
pid <- reg$param_id[reg$lever == lv & reg$block == "control_effect"][1]
response_effect(x, param(reg, pid), param(reg, paste0(lv, "_K50")), param(reg, paste0(lv, "_BASELINE")))
}
rc1 <- vapply(active_levers(cfg), rc_at, 0)
```
**How to read the plot.** The horizontal axis is new spend on one lever, from zero to $2M a year. The vertical axis is the extra reduction that lever delivers in its main effect, the first effect listed for it in the register. Each line is a lever. Each curve flattens because each extra dollar closes a smaller part of the remaining gap.
**What the plot tells you.** At $1M of spend the largest added reduction comes from `r lab_lower(lever_labels(cfg, names(which.max(rc1))))` (`r fmt_pct(max(rc1))`) and the smallest from `r lab_lower(lever_labels(cfg, names(which.min(rc1))))` (`r fmt_pct(min(rc1))`). Curves alone do not rank levers. Each acts on different scenarios, and a lever that touches every scenario, such as logging, is worth more than its main-effect curve suggests. EDR's curve is low partly because `r fmt_pct(param(reg, "EDR_BASELINE"))` of its maximum is already in place.
```{r}
#| label: tbl-lever-matrix
#| tbl-cap: "Lever-by-scenario effects: the maximum frequency and severity reduction each lever can deliver on each scenario."
lm_d <- lever_scenario_matrix(reg, cfg)
names(lm_d)[3:6] <- sc_names
gt_house(lm_d) |> gt::cols_width(Lever ~ gt::pct(18), Status ~ gt::pct(9))
```
**How to read the table.** Each row is a control lever and each column a loss scenario. A cell gives the largest reduction the lever could ever deliver on that scenario: in frequency (how often incidents happen), in severity (how much each costs), or both. A dash means the lever has no effect there. Status shows that every listed lever is in the main search.
**What the table tells you.** Only logging and resilience act on every scenario, and business email compromise is touched by little else in the main search. Identity and MFA has the one large effect on business email compromise and also cuts ransomware frequency, through credential theft and remote-access entry. It began outside the main search and was promoted under a rule set in advance; the [Robustness](robustness.qmd#identity-and-mfa) page explains why.
## Simulator checks
Before any optimization, the simulator must pass five checks. A failed check is reported, not hidden.
```{r}
#| label: tbl-verification
#| tbl-cap: "Simulator verification: each check, what was measured and the result."
#| results: asis
if (is.null(ver)) missing_result("verification") else {
gt_house(ver$table) |>
gt::cols_label(check = "Check", detail = "What was measured", status = "Result") |>
gt::cols_width(check ~ gt::pct(28), status ~ gt::pct(10)) |>
gt::tab_style(gt::cell_text(weight = "bold", color = "#A12A2A"), gt::cells_body(columns = status, rows = status == "Fail"))
}
```
```{r}
#| include: false
vt <- safe(ver$table)
n_pass <- safe(sum(vt$status == "Pass"))
```
**How to read the table.** Each row is one test of the simulator, with the evidence and a Pass or Fail result. The last check compares the spliced tail with a plain lognormal on the same simulated years. Each simulator run took a median of `r safe(sprintf("%.2f", median(ver$timing)))` seconds over 50 timed runs, inside the 0.5-second target, at `r safe(format(ver$n_years, big.mark = ","))` simulated years.
**What the table tells you.** `r n_pass` of `r safe(nrow(vt))` checks pass. The simulator reproduces the no-spend baseline exactly, each lever moves only its own scenarios, more spending never raises expected or worst-year loss, and the Monte Carlo error is under 3%. The spliced tail is now at least as heavy as the plain lognormal. An earlier version matched only the density at the join, which made the tail lighter, the opposite of its purpose.