---
title: "Spending to the Frontier"
subtitle: "Testing Bayesian Optimization on a Cyber Control Budget: Overview"
author: Patrick Lefler
date: today
---
```{r setup}
#| include: false
source("R/_setup.R")
res <- load_all()
cal <- res$calibration; fin <- res$finalists; fr <- res$frontier; rob <- res$robustness; rg <- res$region
app <- appetite_value(reg, cfg, cal$tvar)
budget <- param(reg, "BUDGET_TOTAL")
tg <- safe(fr$targets); kn <- safe(fr$knee)
rf <- safe(robust_frontier_data(rob, app))
fixed <- safe(fr$fixed[order(fr$fixed$budget), ])
first_within <- safe(fixed$budget[which(fixed$tvar <= app / 1e6)[1]])
p_at <- function(b) safe(rf$share[which.min(abs(rf$budget - b))])
reach80 <- safe(rf$budget[which(rf$share >= 0.8)[1]])
mt <- safe(methods_table_data(res))
rt <- safe(ratcor_table(res, reg, cfg))
k <- param(reg, "COST_OF_CAPITAL")
```
All money is in US dollars and all values are illustrative. The firm is synthetic.
## Introduction
::: {.headline}
"We have `r fmt_m(budget, 0)` a year for new cyber controls. Where should it go, and how much protection does each extra dollar buy?"
:::
Boards are asked to approve cyber budgets with little sense of what the money buys. This project works through the question for a synthetic financial services firm with `r fmt_value(param(reg, "ORG_REVENUE"), "USD")` of revenue. The firm faces four loss scenarios: ransomware, business email compromise, data breach and third-party compromise. `r length(active_levers(cfg))` control levers compete for the budget, each with diminishing returns and an evidence grade. The analysis was revised after an external review, which corrected the ransomware frequency and the tail model, moved the optimizer onto the board's tail measure and brought identity and MFA into the main search.
**Approach.** A Monte Carlo simulator turns any allocation into a distribution of annual losses, with every input drawn from a graded assumptions register ([Model](model.qmd)). Bayesian optimization, greedy allocation, an exact optimizer and a full grid search the splits ([Optimization](optimization.qmd)). `r cfg$robustness$n_effect_draws` random parameter draws and stress tests then check whether the answer survives what we do not know ([Robustness](robustness.qmd)). The board's tail measure is **TVaR95**, the average loss in the worst 1-in-20 years.
**Headline results.**
1. **The appetite is a premise, not a finding.** The board's `r fmt_m(app, 0)` appetite on TVaR95 is a design choice, first set against an earlier calibration. Under the corrected calibration, zero-spend TVaR95 is `r safe(fmt_m(cal$tvar, 2))`, `r safe(if (cal$gate) "outside the appetite" else "already inside the appetite")` on base-case values. But it is inside the appetite in only `r safe(fmt_pct(p_at(0)))` of parameter draws.
2. **Recommended split.** The recommended `r fmt_m(budget, 1)` split leans on `r safe(top_levers_text(fin$recommended_alloc, cfg))` and brings TVaR95 to `r safe(fmt_m(fin$rec_metrics$tvar, 2))`. Many nearby splits do almost as well, so it is shown as a range below.
3. **What spend buys in confidence.** `r safe(if (is.na(reach80)) "No budget up to $5M keeps TVaR95 inside the appetite in 80% of parameter draws." else sprintf("Keeping TVaR95 inside the appetite in 80%% of parameter draws first needs %s of spend.", fmt_m(reach80 * 1e6, 2)))` At `r fmt_m(budget, 0)` the share is `r safe(fmt_pct(p_at(budget / 1e6)))`.
4. **The money case rests on how the board prices tail risk.** At a `r fmt_pct(k)` cost of capital on unexpected loss, the recommendation breaks even against no spending only if that charge is `r safe(fmt_pct(rt$breakeven[rt$option == "Recommendation"]))` or more.
5. **How much matters more than how.** The best split beats an equal split by only `r safe(fmt_pct(mt$excess_tvar[mt$method == "Equal split"], 1))` of TVaR95.
::: {.callout-important icon="false"}
## Read the results as a method, not a forecast
The firm, its losses and its control effects are synthetic. Every frequency input and most control-effect inputs are graded weak, expert judgment or gap. The numbers show how the method works and what it would say given these inputs. They are not estimates for any real firm.
:::
## What did not go as expected
```{r}
#| include: false
g6 <- res$ground_truth6
t_eval <- safe(stats::median(res$verification$timing))
ex <- function(m) safe(fmt_pct(mt$excess_tvar[startsWith(mt$method, m)][1], 2))
v2n <- safe(nrow(pareto_front(data.table::rbindlist(lapply(res$v2$runs, `[[`, "archive"), fill = TRUE), c("ale", "tvar"))))
steps_min <- safe(sum(vapply(c("calibration", "verification", "surrogate_demo", "v1", "v2", "v3", "baselines", "ground_truth",
"ground_truth6", "frontier", "finalists", "robustness", "sensitivity", "identity", "transfer"),
function(s) load_result(s, meta = TRUE)$meta$runtime_sec, 0)) / 3600)
```
The study set out to show that Bayesian optimization can find the best split of a cyber budget. Several of the original expectations did not hold, and the results are more useful read with that in mind.
- **Bayesian optimization was not needed.** One simulation takes about `r safe(sprintf("%.2f", t_eval))` seconds, so the full grid of `r safe(format(g6$n_points, big.mark = ","))` splits was affordable, and expected loss can be optimized exactly. Greedy allocation and the exact optimizer both came within `r safe(fmt_pct(max(mt$excess_tvar[startsWith(mt$method, "Greedy")], mt$excess_tvar[startsWith(mt$method, "Exact")]), 2))` of the best split known, while Bayesian optimization ended `r ex("Bayesian optimization (EI)")` above it. The study is best read as a test of the method, which it does not pass on a problem this cheap.
- **The baseline is already inside the appetite.** After the review corrected the ransomware frequency, zero-spend TVaR95 is `r safe(fmt_m(cal$tvar, 2))` against a `r fmt_m(app, 0)` appetite, so the expected story of spending to reach the appetite did not materialize on base-case values.
- **There was no trade-off to map at the fixed budget.** The average-against-worst-year front has `r safe(v2n)` point`r safe(if (v2n == 1) "" else "s")`: the same split minimizes both.
- **The split barely matters.** The best split beats an equal split by `r safe(fmt_pct(mt$excess_tvar[mt$method == "Equal split"], 1))` of TVaR95, and many splits are near-equivalent.
- **The financial case for the spend is weak.** The recommendation breaks even against no spending only if the cost of capital on bad years is `r safe(fmt_pct(rt$breakeven[rt$option == "Recommendation"]))` or more, and insurance cuts worst-year loss far more cheaply in this model.
- **The analysis is slow to rebuild.** The single end-to-end run behind these results took about `r safe(sprintf("%.1f", steps_min))` hours of wall-clock time, so any change to the inputs means an overnight rebuild ([Reproducibility](reproducibility.qmd#repro-limits)).
What did hold up is the method around the optimizer: a graded register, common random numbers, verification checks, a full grid, exact and greedy benchmarks, and robustness tests strong enough to expose these limits.
## Executive summary
```{r}
#| label: fig-exec-frontier
#| fig-cap: "Board frontier: the lowest worst-year loss (TVaR95) the firm can buy at each level of annual control spend. The gray band shows the 10th to 90th percentile of the frontier allocation's TVaR95 across parameter draws."
#| fig-alt: "A falling step line from the zero-spend TVaR95 at the left to the lowest worst-year loss at 5 million dollars, inside a wide gray band that narrows with spend. A dashed amber appetite line, three marked budget points and an amber diamond at the knee."
#| fig-height: 5.6
#| results: asis
if (is.null(fr)) missing_result("frontier") else
plot_board_frontier(fr, app, band = if (is.null(rob)) NULL else data.frame(spend = rf$budget, lo = rf$p10, hi = rf$p90),
zero_tvar = cal$tvar)
```
**How to read the plot.** The horizontal axis is annual spend on new controls and the vertical axis is the average loss in the worst 1-in-20 years. The navy line is the best result found at each spend level on base-case inputs. The gray band shows how far the frontier allocation's result moves when the uncertain inputs are drawn at random. The dashed amber line is the board's `r fmt_m(app, 0)` appetite; circles mark three budgets and the diamond marks the knee.
**What the plot tells you.** The first dollars buy the most. Spending `r safe(fmt_m(tg$spend[1] * 1e6, 1))` takes worst-year loss from `r safe(fmt_m(cal$tvar, 2))` to `r safe(fmt_m(tg$tvar[1] * 1e6, 2))`, while going from `r safe(fmt_m(tg$spend[2] * 1e6, 1))` to `r safe(fmt_m(tg$spend[3] * 1e6, 1))` saves only `r safe(fmt_m((tg$tvar[2] - tg$tvar[3]) * 1e6, 2))` more. The band is wide and sits mostly above the line, because large losses dominate the draws. On base values the line `r safe(if (cal$gate) "crosses" else "starts below")` the appetite, but the band's upper edge `r safe({ b <- rf$budget[rf$p90 > app / 1e6]; if (!length(b)) "never reaches it" else if (max(b) >= max(rf$budget)) "stays above it at every budget shown" else sprintf("stays above it up to %s of spend", fmt_m(max(b) * 1e6, 2)) })`.
```{r}
#| label: tbl-exec-alloc
#| tbl-cap: "Recommended allocation of the fixed annual budget and the range across near-optimal allocations, rounded to $0.05M."
#| results: asis
if (is.null(rg) || is.null(fin)) missing_result("region") else range_table(rg, fin$recommended_alloc, cfg)
```
**How to read the table.** Each row is one control lever. Recommended is the confirmed recommendation's annual amount, rounded to the nearest $0.05M. The three range columns cover every evaluated allocation whose TVaR95 is within `r fmt_pct(cfg$optimization$epsilon)` of the best: the lowest, median and highest amount on that lever. A wide range means the exact amount barely matters. No lever may take more than `r fmt_pct(param(reg, "BUDGET_MAX_SHARE"))` of the budget.
**What the table tells you.** The recommendation funds every lever, with the most on `r safe(top_levers_text(fin$recommended_alloc, cfg, 2))`. The near-optimal ranges are wide, so the board can adjust amounts for practical reasons, such as vendor contracts or hiring, at little cost. The ranking is evidence-sensitive: halving weakly evidenced effects moves the top two levers to `r safe(paste(lab_lower(lever_labels(cfg, rob$top2_shrink)), collapse = " and "))`. Total spend matters more than the exact split.
`r safe(verdict_sentence(rob$verdict))` Details and stress tests are on the [Robustness](robustness.qmd) page.
```{r}
#| label: tbl-ratcor
#| tbl-cap: "Risk-adjusted total cost of risk: expected loss plus spend plus a cost-of-capital charge on unexpected loss, with the charge at which each option breaks even against no spending."
#| results: asis
if (is.null(rt) || !is.data.frame(rt)) missing_result("frontier") else {
gt_house(rt) |>
gt::fmt_currency(c(spend, tvar, ratcor), decimals = 2, pattern = "{x}M") |>
gt::fmt_currency(ale, decimals = 3, pattern = "{x}M") |>
gt::fmt_percent(breakeven, decimals = 0) |>
gt::sub_missing(missing_text = "") |>
gt::cols_label(option = "Option", spend = "Annual spend", ale = "Expected loss", tvar = "TVaR95",
ratcor = sprintf("Risk-adjusted cost at %s", fmt_pct(k)), breakeven = "Break-even charge")
}
```
**How to read the table.** Each row is one option. Risk-adjusted cost adds expected annual loss, the spend, and a `r fmt_pct(k)` annual charge on unexpected loss (TVaR95 minus expected loss), a standard way to price capital held against bad years. The break-even charge is the rate at which the option's risk-adjusted cost equals that of spending nothing; above it, spending pays. The `r fmt_pct(k)` rate is a design assumption.
**What the table tells you.** At a `r fmt_pct(k)` charge the cheapest option is `r safe(lab_lower(rt$option[which.min(rt$ratcor)]))`. The recommendation needs a charge of `r safe(fmt_pct(rt$breakeven[rt$option == "Recommendation"]))` to break even, well above typical costs of capital, so on these inputs the spend is hard to justify on expected cost alone. The case for it rests on the board's aversion to bad years, on uncertainty, or on insurance being unavailable (see [Optimization](optimization.qmd#controls-or-insurance)).
**Decisions for the board.**
1. **How much to spend, and with what confidence.** The frontier and the probability of meeting the appetite show what each budget buys. The knee sits at `r safe(if (is.na(kn$budget)) "no budget in range" else fmt_m(kn$budget * 1e6, 2))`.
2. **Whether `r fmt_m(app, 0)` is the right appetite, and how tail risk should be priced.** Both are design choices that drive the answer.
3. **Controls, insurance or both.** In this model, risk transfer cuts worst-year loss far more cheaply than controls; real quotes would decide it.
4. **Whether to fund better evidence.** Loss sizes and frequencies drive the risk level; several control effects are graded gap.
### Where the evidence is weakest
```{r}
#| label: tbl-gaps
#| tbl-cap: "Active model inputs with no direct evidence (gap) or resting on expert judgment."
gr <- gap_rows(reg)
gt_house(data.frame(ID = gr$param_id, Input = gr$parameter, Grade = gr$evidence_grade,
Base = mapply(fmt_value, gr$base, gr$unit),
Range = paste(mapply(fmt_value, gr$low, gr$unit), "to", mapply(fmt_value, gr$high, gr$unit)))) |>
gt::cols_width(ID ~ gt::pct(18), Input ~ gt::pct(42))
```
**How to read the table.** Each row is an input that enters the main model but has no direct evidence (gap) or rests on expert judgment (expert). Base is the value used and Range is the span tested in the robustness draws. Inputs graded gap are placeholders that should be replaced by structured expert elicitation or the firm's own data before any real budget decision.
**What the table tells you.** `r nrow(gr)` inputs fall in these two grades, `r sum(gr$evidence_grade == "gap")` of them gaps. They include the effects of privileged access management and logging, the median ransomware loss and the common-shock probability. Several levers therefore compete for budget on effect sizes nobody has measured. The robustness tests carry this uncertainty through, but they cannot remove it. Replacing these rows with measured values is the most useful next step.