Lap 19 of the 2026 Las Vegas Grand Prix. Sergio Pérez has hit the wall after contact with Camara, and the
In This Chapter
- 40.1 What we built: 41 modules, one per chapter
- 40.2 The rule that makes validation honest: only what was known before the race
- 40.3 Running it: the 2026 Las Vegas Grand Prix
- 40.4 The robust strategy and the outcome distributions
- 40.5 Validation: six races, pre-race inputs only
- 40.6 What we know is wrong, measured
- 40.7 The season backtest: every dry race of 2025 and 2026
- 40.8 Running it on the next Grand Prix
- 40.9 Closing the book
- Spaced Review
- Project Checkpoint: cli.py, report.py and project/tests/
- Chapter Summary
- The last lap
Chapter 40 — Capstone: Your F1 Race Strategy Simulator — Built, Validated, and Ready for the Next Grand Prix
Lap 19 of the 2026 Las Vegas Grand Prix. Sergio Pérez has hit the wall after contact with Camara, and the safety car is out. On the timing screen, the pit-lane column fills up almost at once. In our data, 16 of the 20 cars that made a stop that night made their first one on lap 19. Max Verstappen, who started from the front of the grid on a soft set already three laps old, comes in with everyone else, takes mediums, and wins by 0.639 s from Lando Norris. Oscar Piastri, 17th on the grid, finishes third.
Now rewind to the evening before. Qualifying is over, and nobody knows a safety car is coming. Suppose you had typed one line into a terminal:
python -m boxbox validate --year 2026 --gp vegas
Box Box, the simulator you have built one module at a time across 39 chapters, would have told you this, using only information available before the lights went out:
- The clean-race optimum is one stop, SOFT to HARD, on lap 15.
- For Verstappen's actual tyres (a three-lap-old SOFT, then MEDIUM), the best stop is lap 22, and anywhere from lap 18 to lap 27 costs less than a second. He stopped on lap 19, inside that window, because the safety car made it cheap.
- The robust policy for the pole car is a flexible one-stop: plan one stop and take a second only if a neutralisation makes it pay. It gains 0.79 s on average over a rigid one-stop in clock-only races. A planned two-stop loses 14.0 s.
- Who wins? The simulator gives Verstappen 20.9% and makes Kimi Antonelli, fastest in qualifying but sixth on the grid after a power-unit penalty, the favourite at 29.9%. The gradient-boosting model from Chapter 26 gives Verstappen 65.9%.
So the simulator got the number of stops right and the timing window right. It got the compound wrong: it loved the HARD, and no car ran a HARD tyre in that race. And it badly underrated the man on pole.
That mixture of hits and misses is the honest result of a strategy model built on free public data, and it is what this chapter is about. We assemble every module into one tool and run it. Then we test it on six real races and on every dry Grand Prix of 2025 and 2026. We explain every miss we can, and say plainly which ones we can't. Finally, we show you how to point it at the next race.
🏎️ Fan Track: Read 40.1, 40.3–40.5 and 40.9. You can skip the code. The figures and the "Validation" tables tell the story, and 40.9 closes the book. 📊 Analytics Track: This is your chapter. Run every script, read the adapter in
cli.py, and do the season backtest (40.7) and Case Study 2 yourself. 🎰 Betting Track: Focus on 40.4 and 40.6. The simulator's probabilities are under-confident about the front of the grid, and that matters before you compare them with a price (Chapter 38).
40.1 What we built: 41 modules, one per chapter
Box Box is a Python package at project/boxbox/. Each chapter added exactly one module. This chapter adds
three things: cli.py (the command line plus a thin adapter layer that joins the modules), report.py (an
HTML report) and project/tests/ (smoke tests). Before we run anything, it is worth looking at what is
actually there. Our first script does not import a single module. It parses the source files with
Python's ast module and counts what each one contains and what it imports.
# code/01_pipeline_map.py (excerpt): who imports whom, read from the source
tree = ast.parse(src)
pub = [n for n in tree.body if isinstance(n, (ast.FunctionDef, ast.ClassDef))
and not n.name.startswith("_")] # public functions and classes
for node in ast.walk(tree): # includes imports inside functions
if isinstance(node, ast.ImportFrom) and node.level > 0: # relative: from . import wet
imp |= {a.name for a in node.names} if not node.module else {node.module}
elif isinstance(node, ast.ImportFrom) and node.module and node.module.startswith("boxbox"):
imp.add(node.module.split(".")[1])
# then: everything reachable from cli and report, transitively, is "in the pipeline"
41 modules, 14,963 lines of code (blank and comment lines excluded), 603 public functions and classes
modules lines
role
analysis module (not in simulate) 17 5647
assembly (Ch 40) 2 1105
called by the pipeline 14 5723
used inside a pipeline module 8 2488
cli imports directly: conditions, data, degradation, montecarlo, neutralisation, overtaking, pace,
predict, regs, regs2026, reliability, report, strategy, tyres

📊 Figure (described): One bar per module, from Chapter 1's
physicsat the bottom to Chapter 40'scliandreportat the top, with length showing lines of code. Blue modules are called directly by thesimulatecommand, green ones are used inside those, and grey ones are analysis tools that the race simulation does not need. The largest arecli(854 lines) andmontecarlo(693).
Notice what the grey bars are. The physics of Part I (physics, pacejka, brakes, setup, lapsim)
explains why a car is fast. But the race simulator does not compute pace from first principles. It
takes pace from timing data. That is a deliberate choice, and 40.6 shows why: out of the box, the lap
simulator is several seconds off. The analysis modules still earn their place. They are how you
understand a result the simulator produces.
The pipeline, as cli.py's docstring lays it out:
| Step | Modules (chapter) | What they contribute |
|---|---|---|
| 1 | data (2) |
the race, its qualifying session and its weekend |
| 2 | pace (20), degradation (22), tyres (4) |
race pace from the qualifying gap; pre-race deg by compound and circuit; stint caps |
| 3 | strategy (12) |
the clean-race optimum: every legal plan, priced |
| 4 | neutralisation (14), start (17), driver (9), reliability (37), overtaking (35), conditions (36) → montecarlo (27) |
hazard and incident library, lap-1 fates, lap noise, DNF rates, the pass target, P(rain): the race engine's ingredients |
| 5 | predict (26) |
a gradient-boosting second opinion |
| 6 | regs (28), regs2026 (29) |
minimum stops, tyre allocation, legality; the 2026 pit-loss shift |
| 7 | viz (25), report (40) |
the charts and the HTML report |
If you want to revisit the pieces before assembling them, the five that matter most are the optimiser of Chapter 12, the safety-car hazard of Chapter 14, the degradation model of Chapter 22, the prediction model of Chapter 26 and the race engine of Chapter 27.
📐 Definition: The adapter layer is the code that turns one module's output into another's input without changing either module. In Box Box it is the set of functions in
cli.py:resolve_race,build_inputs,clean_optimum,race_setup,simulateandvalidate.🔄 Check your understanding 1. Why does the race simulator take pace from qualifying and race timing instead of from the lap simulator of Chapter 11? 2. Which three modules does the Monte Carlo engine import on its own, without the adapter?
Answer
1. Because timing data is measured and the uncalibrated lap simulator is several seconds off (40.6); pace is the input the strategy is most sensitive to. 2.neutralisation,startanddriver(the pipeline map's import column formontecarlo).
40.2 The rule that makes validation honest: only what was known before the race
The most important line in cli.py is not a model. It is a filter:
before = lambda df: df[df.date_start < ctx.date] # every table is cut at the race's start time
Every input of a past race comes from races that started before it: the degradation model, the stint caps, the pit-loss pool, the safety-car hazard and its circuit multiplier, the incident library, the SC/VSC stop-loss ratios, the pass counts and the team DNF rates. Only two things come from the race itself, and both were public at the start: the starting grid (Jolpica, with penalties applied) and the starting tyres (each car's first stint).
Why insist on it? Because a model validated on information it could not have had will always look better than it is. Chapter 26 measured this for prediction. In its walk-forward test, leaky features faked about half of a naive model's gain. A strategy model leaks just as easily. Fit the degradation on the race's own stints, and the stop lap you "predict" has already seen the stops.
⚠️ Common pitfall: the module defaults leak the future. Several modules ship with book-wide constants, such as
neutralisation.HAZARD_2023_26(hazards measured over all 91 races of 2023–26) or a pit-loss table pooled over every season. These are the right defaults for describing the sport. Used to "predict" a 2025 race, they quietly include 2026. The adapter recomputes the hazard (nz.hazard_by_phase), the circuit multiplier and the incident library from the races before the date. A smoke test checks it: for the 2026 Las Vegas GP the library is built from exactly 90 earlier races.
The adapter fixes three more integration problems without editing the modules:
- Phantom stops. OpenF1 sometimes inserts a stint with no laps (
lap_end < lap_start) when a car passes through the pit lane on the same set, or starts a new stint on the same set.strategy.actual_strategieswould count those as stops. The book's data build now removes most of them at the source: across every session it dropped 132 zero- or negative-length stints and merged 305 same-set continuations into the stint before. The adapter'sactual_strategieskeeps its own check as well. It drops zero-length stints (none are left) and merges a stint into the previous one when the compound is the same and the start age is within 2 laps of where the previous stint ended. That slightly looser rule still changes the stop count of 37 driver-races in 7 of the 91 Grands Prix: 15 at the 2025 Australian GP, 13 at the 2025 Canadian GP, 5 at the 2026 Monaco GP and one each at four other races. - Pit lanes change. At Singapore, the canonical green-flag pit loss was 28.903 s in 2023 and 29.658 s in 2024, then 23.207 s in 2025 and 24.439 s in 2026, after the pit-lane limit went from 60 to 80 km/h. A pool of every earlier year would price a 2026 stop with the old pit lane. The adapter uses the circuit's latest edition when it has at least 10 used stops, and widens the pool only when it does not.
- The 2026 shift. Chapter 29 measured green-flag pit loss in 2026 at +1.22 s against 2023–25 at the
same circuits. When a 2026 race is priced with a 2025 pool, the adapter adds
regs2026.regime(2026) .pit_loss_delta_sto each pooled stop.
For 2026 Singapore those two fixes give a pit loss of 24.43 s (2025's 23 stops, each + 1.22 s). The race itself, measured afterwards, came in at 24.439 s. Pooling all three earlier years would have given 29.15 s.
🔍 Why this works: A pre-race filter turns validation into a forecast test. Every number the model uses existed at the moment of the decision, so its errors are the errors a strategist using the same public data would have made. Without the filter you measure something else: how well the model describes the race. That is a useful question, but it is a different one. We will use both. The hindsight optimum in 40.5 answers the descriptive question on purpose, and labels itself as hindsight.
40.3 Running it: the 2026 Las Vegas Grand Prix
Here is the command again, and the first block of what it prints:
=== 2026 Las Vegas Grand Prix: inputs (pre-race) ===
pace: race gap = 0.971 x quali gap (16 earlier dry races, n = 306); pace SD 0.522 s/lap; base lap 98.151 s
deg (default fuel correction): SOFT 0.045, MEDIUM 0.036, HARD 0.017 s/lap; stint caps S 32, M 25, H 34
pit loss: median 23.39 s (17 green stops at this circuit in 2025 (canonical pit_loss) + 1.22 s on 2023-25 stops (2026 shift, regs2026.regime))
neutralisations: k = 1.52; P(>= 1 incident) = 0.83; library 117 incidents
reliability: field DNF 0.185; lap-1 share 0.0069; passes target 70.9 (mean green passes in 3 earlier race(s) here x 1.31 (2026 season so far vs 2023-25))
conditions: qualifying track 15.7 C, air 13.2 C; rain earlier in the weekend -> P(rain in race) 0.35
rules: minimum stops 1; allocation {'HARD': 2, 'MEDIUM': 3, 'SOFT': 8}
Read it line by line, because each line is a chapter.
- Pace comes from Chapter 20 by way of Chapter 27. In the 16 earlier dry races of 2026, a driver's race gap was 0.971 times his qualifying gap (n = 306 driver-races). The scatter around that line, 0.522 s per lap, becomes every car's pace uncertainty.
- Degradation is Chapter 22's
DegModel, fitted on every earlier dry race and shrunk towards the compound mean. It uses the toolkit's fuel correction (an assumed 100 kg × 0.03 s/kg). The HARD comes out at 0.017 s/lap, well under half the SOFT's 0.045. - Pit loss is the canonical green-flag measure from the latest edition, shifted for 2026.
- Neutralisations: the Las Vegas hazard multiplier is k = 1.52, which gives an 83% chance of at least one SC, VSC or red flag in 50 laps.
- Reliability: in the 2026 rounds before Las Vegas, 18.5% of starters failed to finish.
- Overtaking: the pass target is 70.9 green on-track passes. The engine cannot reach it (it simulates 60.3 at its bound), a limit Chapter 27 also met at this circuit.
- Conditions: the weekend's earlier sessions logged rain, so Chapter 36's weekend rule gives a 35% chance of rain in the race (13 of 37 races after a wet weekend, 2023–26).
- Rules:
regssets the minimum stops and the 2026 allocation of 2 HARD, 3 MEDIUM and 8 SOFT sets.
The adapter that builds all of this is long but plain. Here is its spine:
# project/boxbox/cli.py, build_inputs (excerpt)
q2r = quali_to_race(ctx.year, ctx.round) # pace: the season's quali -> race link
ST = before(stint_table_all()) # Ch 22 stint table, earlier races only
dm = dg.DegModel(use_temp=False).fit(ST) # pre-race deg model (M2, no temperature)
deg = {c: max(dm.predict(c, ctx.circuit), DEG_FLOOR) for c in COMPS}
S = before(_summary_all()) # race control, earlier races only
hazard = {r.phase: r.lam for r in nz.hazard_by_phase(S).itertuples() if r.phase in nz.PHASES}
k = nz.circuit_multiplier(ctx.circuit, hazard, S)["k_pooled"][0]
shr = rel.team_dnf_shrunk(yr, use) # Ch 37: DNF rates, shrunk by team
target = same_era.green.mean() # Ch 35: green passes at this circuit
weather = cond.session_conditions(ctx.quali_key) # Ch 36
alloc = regs.rule_set(ctx.year).dry_allocation # Ch 28
The clean-race optimum
Step 3 hands those inputs to Chapter 12's exhaustive optimiser. It prices every legal compound sequence with one to three stops, at every combination of in-laps, and keeps the best in-laps for each sequence:
=== clean-race optimum (strategy.optimise, 100 compound sequences priced) ===
sequence n_stops stop_laps gap_s legal
S-H 1 (15,) 0.00 True
H-S 1 (35,) 0.34 True
M-H 1 (15,) 1.03 True
H-M 1 (35,) 1.47 True
M-S 1 (26,) 10.00 True
S-M 1 (24,) 10.10 True
best one-stop 15 (1-s window 10-20)

📊 Figure (described): Seven rows of stint bars over 50 laps. The model's top four plans all use a HARD stint and cost under 2 s more than the best (S-H, stop on lap 15). S-M, the plan almost the whole field ran, is sixth at +10.1 s. The bottom row is Verstappen's actual S-M, stopping on lap 19, which costs 0.4 s against the best stop lap for his own tyres.
Why lap 15? Anchor B gave us the closed form for a linear model. With the opening set on compound 1 (deg $d_1$, starting age $a_0$) and the second on compound 2, over $N$ laps, the single-stop optimum sits where the two sets' lap-time penalties cross:
$$s^* \approx \frac{d_2 N - d_1 a_0 + o_2 - o_1}{d_1 + d_2}$$
In plain English: stop when the old tyre's extra time per lap has grown to match what the new tyre will lose by the flag. Compound offsets $o$ shift the balance. For SOFT → HARD on new sets ($a_0 = 0$), with the book's pooled offsets ($o_S = -0.136$, $o_H = -0.039$ s/lap vs MEDIUM):
$$s^* = \frac{0.017 \times 50 - 0 + (-0.039) - (-0.136)}{0.045 + 0.017} = \frac{0.947}{0.062} \approx 15.3$$
That is the optimiser's lap 15. Now Verstappen's tyres: a SOFT already 3 laps old, then MEDIUM ($d_2 = 0.036$, $o_M = 0$):
$$s^* = \frac{0.036 \times 50 - 0.045 \times 3 + 0 - (-0.136)}{0.045 + 0.036} = \frac{1.801}{0.081} \approx 22.2$$
The exact search says lap 22, with the 1-s window running from lap 18 to 27. The formula ignores the warm-up penalty and the stint caps. Here it lands within a lap of the full search anyway, which is a good sanity check on both.
📺 On the broadcast: When the graphics show a "pit window opening on lap 18", this is the idea behind it. There is a stretch of laps where stopping costs almost the same whichever lap you choose. The commentators then wait for an excuse: traffic, an undercut threat, a safety car. At Las Vegas the excuse arrived on lap 19, and 16 of the 20 cars that stopped took it.
🧩 Productive struggle: Before reading on, look at the table again. The model rates HARD as the best second tyre by about 10 s. Nobody ran a HARD in the race. List three reasons the model could be wrong about the HARD at this circuit, using only what Box Box's inputs contain and lack.
One way to think about it
(1) The offsets and warm-up penalties are pooled across circuits: the HARD's warm-up penalty in the model is 0.117 s, measured across all dry races, and a 15.7 °C track is among the coldest the cars see. The data cannot measure tyre temperature, so the model cannot know whether the HARD would come in at all. (2)DegModelshrinks a circuit towards the compound mean, and Las Vegas has few HARD stints in its history, so its HARD deg is mostly a prior. (3) The model has no allocation memory: it does not know which sets each team had left after qualifying. All three are inputs, not optimiser failures.
40.4 The robust strategy and the outcome distributions
A clean-race optimum is where a strategist starts, not where they stop. Chapter 27's engine races the whole field thousands of times, drawing what nobody controls: safety cars, lap-1 shuffles, retirements, lap noise, how much each stop really costs and how the tyres really behave. The robust strategy is the policy that does best across all those races, not in the one race where nothing happens.
Box Box runs the same simulated races once per policy for the car you care about (common random numbers, so the differences are about the strategy, not the luck). The default car is the one on pole:
=== robust strategy for VER (5,000 races per policy, same races) ===
policy mean_pos median_pos p_win p_podium p_points exp_points d_time_vs_ref p_better_pos p_worse_pos mean_stops
one-stop 5.779 3.0 0.197 0.513 0.839 13.025 0.000 0.000 0.000 0.955
two-stop 6.957 5.0 0.090 0.317 0.815 9.869 13.233 0.066 0.534 1.910
flexible 5.674 3.0 0.205 0.528 0.842 13.289 -0.837 0.058 0.014 1.222
robust (highest expected points): flexible
The flexible policy (one or two stops, decided lap by lap) is the robust choice. It is worth 0.26 expected points over a rigid one-stop, and it finishes behind the one-stop in only 1.4% of races. A planned two-stop costs about 3.2 points and is worse in 53.4% of races. A mean stop count of 0.955 for "one-stop" is not a bug: in about 4.5% of races the car retires before its stop.

📊 Figure (described): Three step histograms of Verstappen's simulated finishing position, one per policy, over the same 5,000 races. The one-stop and flexible lines nearly coincide, with a median of P3 and a long tail of retirements at the far right. The two-stop line is shifted right (median P5). The legend gives each policy's 10–90% range.
The clock-only view strips out traffic and the other 21 cars. It runs identical "ghost" cars, which is Anchor C's measure:
=== clock only (ghost cars, 10,000 races): time vs the one-stop policy ===
policy mean_diff_s median_diff_s p_better p_worse mean_stops
one-stop 0.000 0.000 0.000 0.000 1.000
two-stop 13.973 14.137 0.152 0.847 2.000
flexible -0.786 0.000 0.116 0.052 1.283
if it rains (hazard x 2.38):
two-stop 11.876 11.74 0.211 0.788 2.000
flexible -1.503 0.00 0.207 0.100 1.535

📊 Figure (described): Two distributions of race time minus the one-stop plan over 10,000 simulated races. The two-stop sits almost entirely to the right of zero (median +14.1 s). The flexible policy is a spike at exactly zero (no neutralisation made a second stop pay), with a thin tail to the left: the races where it did.
This is Anchor C's lesson again, at a different circuit. The option to stop under a safety car is worth having. The commitment to a second stop is not. Even when we raise the incident hazard by Chapter 36's wet-race ratio of 2.38, the planned two-stop still loses 11.9 s on average, and the flexible option gains 1.50 s.
🧪 Illustrative model: the passing model inside the engine (a logistic pass probability in pace advantage, with its threshold calibrated to the circuit's measured pass count), the dirty-air penalty and the SC gap compression are Chapter 27's stated engine parameters, measured where the data allow and assumed where they do not. The rain row raises only the incident hazard; the engine has no wet tyres.
Who wins?
=== outcome distribution, 10,000 field races (top 10 by expected position) ===
code grid p_win p_podium p_points p_dnf median_pos p10 p90 exp_points mean_stops
ANT 6 0.299 0.634 0.888 0.108 3.0 1.0 16.0 15.427 1.250
RUS 2 0.173 0.488 0.874 0.112 4.0 1.0 16.0 12.904 1.247
NOR 3 0.163 0.472 0.858 0.129 4.0 1.0 18.0 12.511 1.229
VER 1 0.209 0.522 0.834 0.157 3.0 1.0 18.0 13.155 1.232
LIN 5 0.045 0.214 0.847 0.087 6.0 2.0 13.0 8.360 1.248
GBM second opinion (Ch 26, trained on earlier seasons): VER 0.659, ANT 0.136, NOR 0.095, RUS 0.073, HAD 0.010

📊 Figure (described): Horizontal bars for the ten cars with the best expected position: dark blue for P(win), light blue for P(podium), and orange diamonds for the gradient-boosting model's P(win). On the right is each car's real finishing position. The simulator's favourite, Antonelli (grid 6), finished fourth. Verstappen, whom the gradient-boosting model rated at 0.66, won.
The two models disagree because they see different things. The Monte Carlo engine sees pace. Antonelli's qualifying lap was 0.258 s quicker than Verstappen's, so the engine rates his race pace as faster and lets him fight through from sixth. The gradient-boosting model sees history. Over 2014–26, the pole-sitter won 55.7% of races, and the grid slot is the strongest feature it has. Neither is "right" on one race. But 40.6 shows that, race after race, the engine's view of the front row is too modest. Its pace uncertainty is one number for the whole field, so it lets a midfield car that has a good day beat a pole-sitter that has an ordinary one too often.
🎰 Betting Track aside: Ray would say it before anyone: a model that gives the pole-sitter 21% at a circuit where the race is decided by a safety car is not "finding value". It is telling you about its own pace-uncertainty assumption. Chapter 38's edge calculation is only as good as the probability you feed it.
🔄 Check your understanding 1. Why does the flexible policy show a mean of 1.222 stops for Verstappen but 1.283 in the ghost runs? 2. What does "common random numbers" buy us in the policy comparison?
Answer
1. The field runs include retirements (a retired car makes no more stops) and a lap-1 shuffle that changes which incidents are worth stopping for. Ghosts never retire and have no traffic. 2. The same incidents, lap-1 outcomes and stop draws hit every policy, so the difference between policies has far less noise than two independent runs (Chapter 27 measured the gain at about 1,562 times in variance).
40.5 Validation: six races, pre-race inputs only
The capstone has to answer one simple question: does the simulated optimal strategy
match what the winning team actually did? "Match" needs a definition before we look, or we will be
tempted to choose the one that flatters us. Box Box's validate checks three things, each fixed in
advance:
📐 Definition: For a validated race, the simulator agrees on stops when the clean-race optimum makes as many stops as the winner did. It agrees on timing when the winner's stop falls inside the model's 1-s window for the winner's own compounds and starting set (one-stop races), or every stop is within 3 laps of the model's best (multi-stop races). It agrees on compounds when the optimum uses the winner's compounds, or the winner's sequence is within 1 s of the optimum. The verdict is AGREE (all three), PARTIAL or MISS (none).
Why judge timing on the winner's own tyres? Because the compound choice and the stop lap are separate decisions, made with different information. The compound was often fixed by what a team had left after qualifying, which the data do not show. Asking "given those tyres, did they stop when the model would have?" isolates the part of the call the degradation model is supposed to make. This is Anchor B's question, asked of six races.
The suite (code/03_validation_suite.py) runs the full validate pipeline for the 2026 Las Vegas GP and five
other 2025–26 races, chosen before the runs for what each one tests: Anchor B (Mexico City 2025), Anchor C
(Singapore 2026), the race Chapter 27 used for its pre-race test (United States 2026), a high-degradation
three-stop winner (Barcelona 2026), and a one-stop win over a two-stopping team-mate (Hungary 2025).
=== Summary ===
race winner grid actual stop_status model own_best error window verdict
2026 Las Vegas Grand Prix VER 1 S-M 19 SC S-H 15 22 -3 18-27 PARTIAL
2025 Mexico City Grand Prix NOR 1 S-M 34 GREEN S-H 30 35 -1 31-39 PARTIAL
2026 Singapore Grand Prix VER 1 S-M 32 GREEN M-S 36 26 6 20-31 PARTIAL
2026 United States Grand Prix ANT 1 M-H 24 GREEN M-H 27 27 -3 23-31 AGREE
2026 Barcelona Grand Prix HAM 2 S-H-M-H 11, 27, 41 GREEN/GREEN/VSC S-H 29 13, 32, 47 -2, -5, -6 - MISS
2025 Hungarian Grand Prix NOR 3 M-H 31 GREEN M-H-H 24, 47 35 -4 32-39 PARTIAL
Stops agree 4/6; timing agrees 3/6; compounds agree 3/6; verdicts {'PARTIAL': 4, 'AGREE': 1, 'MISS': 1}
Mean P(win) given to the winner: simulator 0.305, GBM 0.413; mean Brier (win) simulator 0.617, GBM 0.540

📊 Figure (described): One row per race. The shaded bar is the model's 1-s window for the winner's own tyres, the vertical tick is the model's best lap, and the orange marker is where the winner actually stopped (a square means the stop came under a safety car or VSC). Mexico City, the United States and Las Vegas sit inside their windows. Singapore and Hungary sit just outside. Barcelona's winner made three stops, so the row is annotated rather than drawn.
One agreement, four partials and one miss. Here is each race in turn, with the reason behind every miss. The reasons are what you learn from.
2026 Las Vegas: right count, right window, wrong tyre. We met this one in the hook. The stop count and
timing agree, though the safety car chose the lap, not the model. The compound miss is structural. Box Box
ranks Verstappen's S-M sixth (+10.1 s), and the race summary from data.RaceData shows that no car ran a
HARD. The adapter flags it: "the model's choice was one the teams rejected outright". The hindsight line
is also telling. On the race's own stints the SOFT and MEDIUM slopes come out negative (−0.037 and
−0.027 s/lap at the default fuel correction). The timing data are consistent with a cold street track whose grip
improved faster than the tyres wore, and with negative wear a linear model has nothing to optimise.

📊 Figure (described): Gap at the line to Verstappen for the leading cars over 50 laps, with the safety-car period from lap 19 shaded and open circles at each in-lap. Almost every circle sits on lap 19, where the gaps collapse. After the restart Norris, Piastri and Antonelli run within a few seconds of Verstappen to the flag, and Russell (grid 2) drops back in the final laps.
2025 Mexico City (Anchor B): one lap from the anchor, for a stated reason. Norris stopped after lap 34. For his SOFT → MEDIUM, Box Box's pre-race model says lap 35, window 31–39, and prices his actual stop at 0.05 s. Chapter 22's Anchor B said lap 36, window 33–40. The difference is in the inputs. Chapter 22 fitted the race's own early stints; Box Box, working the night before, has only the races before it, and its history-based SOFT rate (0.061 s/lap) is a little higher than what the race showed (0.054). A faster-wearing first set moves the best stop a lap earlier. Given the anchor's race-stint inputs, the assembled tool returns lap 36, window 33–40, exactly (Case Study 1). Both windows contain the actual stop, so the anchor's lesson holds: the cost curve is flat, and a lap either way is almost free. The compound check fails for the same reason as at Las Vegas: the model prefers HARD to MEDIUM for the second stint by about 11 s. Case Study 1 runs this race through three input sets.
2026 Singapore (Anchor C): the leader waited. Verstappen ran S-M and stopped on lap 32. The model's best for those tyres is lap 26, with a window of 20–31, so the timing check misses by one lap. The cars behind tell the rest of the story. Leclerc (P2) and Antonelli (P3) stopped on laps 24 and 23, inside the window, then stopped again under the lap-39 VSC. Verstappen and Norris both went to lap 32 and one-stopped. A plausible reading of the timing data is that the leader, with no car close enough to undercut him, could run longer than the deg model's optimum at a cost the model puts at 1.20 s. That is track position, which the clean-race model does not price. The robust policy for the pole car here is flexible, and in the real race the two cars that used the flexible option finished second and third, behind a one-stop.
2026 United States: the full agreement. Antonelli ran M-H, stopped on lap 24, and won from pole. The model's best for his tyres is lap 27, window 23–31, and M-H is also the model's top-ranked plan overall (stop on lap 27). All three checks pass.
2026 Barcelona: the inputs failed, not the optimiser. Hamilton won with three stops (S-H-M-H, laps 11,
27 and 41, the last under a VSC). Box Box wanted one stop. The pre-race degradation was 0.067 / 0.058 /
0.050 s/lap (S/M/H), close to the book's pooled medians, because DegModel shrinks every circuit towards
its history. The race itself ran at 0.237 / 0.182 / 0.124 s/lap, roughly three times higher. Given those
numbers in hindsight, the same optimiser picks M-H-H (laps 17 and 41), which is what Russell (P2, laps 12 and
36) and Norris (P3, laps 13 and 35) actually ran. A degradation model that could not see Barcelona's
2026 tyre behaviour coming could not call a three-stop race, however good its optimiser.
2025 Hungary: the winner beat the model. The model's plan is M-H-H (laps 24 and 47), and that is almost exactly what Piastri (P2, laps 18 and 45), Russell (P3) and Leclerc (P4) ran. Norris one-stopped on lap 31 and won. Box Box ranks his M-H tenth, 3.17 s slower than the two-stop. The model is not wrong that the two-stop was faster in a clean race on its inputs. Norris took a slower plan that kept track position at a circuit where passing is hard, and the race did not punish it. Chapter 22's case study of this race found the same thing: race deg on the opening MEDIUM stints was a median 0.016 s/lap, much lower than any pre-race estimate. On the race's own stints the hindsight optimiser agrees that one stop was enough, although its SOFT slope is negative (−0.037 s/lap), so the lap it picks means nothing.
🔍 Why this works: Separating what from when is what makes the misses explainable. Of the four partials, every failed check traces to one named cause: a compound the model misprices (Las Vegas, Mexico City), track position that the clean-race model ignores (Singapore, Hungary), or an input outside history (Barcelona). A single "did it match?" score would have mixed those together.
The probabilities

📊 Figure (described): For each of the six races, two bars: the simulator's P(win) for the eventual winner (blue) and the gradient-boosting model's (orange), with the winner's grid slot written above. A dashed line marks the pole-to-win rate of 2023–26 (62.6%). The simulator's bars are lower than the gradient-boosting bars in four of the six races, and lower than the base rate in every one.
The simulator made the winner its favourite in three of the six races (Mexico City, Singapore, United States), and the gradient-boosting model in the same three. Averaged over the six, the simulator gave the winner 0.305 and the gradient-boosting model 0.413. The gradient-boosting model also had the better mean Brier score (0.540 against 0.617, summed over the field; lower is better). Six races cannot rank two models, but the direction matches what Chapter 27 found over 15 races, and 40.6 measures it properly.

📊 Figure (described): Five small panels, one per one-stop winner. Each panel shows modelled race time against stop lap for the winner's own compounds, with the 1-s window shaded and the actual stop marked. Every curve is a shallow bowl: within a few laps of the best lap the cost stays under one second, and it climbs steeply only at the ends.
The flat bottoms are Anchor B's lesson in picture form. Within the window, the choice of lap costs less than the gap between two cars in clean air. The real decision is made by things outside the deg model: where the car ahead is, whether a safety car comes, how much life the driver says the tyre has left.
📋 Try it: Call the pit stop (2026 Singapore, lap 31). You are on Verstappen's pit wall. He leads on SOFTs fitted at the start, 31 laps old. The model's one-stop window is laps 20–31, and the stop costs 24.4 s. Leclerc and Antonelli, behind you, stopped on laps 24 and 23 and are on MEDIUMs. Do you box this lap, or extend?
What happened, and what the model says
Verstappen stayed out to lap 32 and stopped once, then won. The model prices lap 32 at 1.20 s above its best lap for those tyres. The cars that stopped early stopped again under the lap-39 VSC (Leclerc's VSC stop cost 12.48 s by the near-field measure, Chapter 14). In the field simulation the robust policy for the pole car is flexible: extend, and keep the option of a cheap second stop. Box Box's call and the real one differ by a lap, and the clean-race model prices that difference at about a second.🔄 Check your understanding 1. Barcelona 2026 is a MISS on all three checks. Which one input, changed in hindsight, makes the same optimiser recommend what the second- and third-placed cars ran? 2. Why is it fair to judge the timing on the winner's own tyres, rather than against the model's favourite compounds?
Answer
1. The degradation: on the race's own stints (0.237 / 0.182 / 0.124 s/lap) the optimiser picks M-H-H on laps 17 and 41, the plan Russell and Norris ran. 2. The compound choice depends on sets left after qualifying and on tyre behaviour the data cannot see. Judging the stop lap for the tyres actually fitted tests only the decision the degradation model is meant to make.
40.6 What we know is wrong, measured
Every model in this book has carried its caveats. A capstone should measure the biggest of them, not just
repeat them. code/04_known_weaknesses.py does four.
1. The pole-sitter problem
Chapter 27 found that the engine is under-confident about pole-sitters. In its 15-race test the mean simulated P(win) for the pole car was 0.390, against a 2014–25 base rate of 0.536. The cause is structural: every car gets the same pace uncertainty, the season's residual SD after the qualifying link (0.522 s per lap at Las Vegas). Every simulated race draws a fresh pace offset for each car. With 22 cars, someone in the midfield draws a good one and beats the pole-sitter far more often than happens in reality.
We reran every dry 2026 race from round 4 on (14 races), with pre-race inputs, at the measured SD and at half of it:
1. Pole calibration, 2026 dry races R4-R21 (n = 14): grid-1 car won 9/14 = 0.643 [0.388, 0.837]
mean_p_grid1 mean_p_winner brier logscore
scale
0.5 0.477 0.400 0.528 1.203
1.0 0.395 0.336 0.578 1.355

📊 Figure (described): Left: the simulated P(win) of the car starting first in each of 14 dry 2026 races, at the measured pace SD (blue circles, mean 0.39) and at half of it (green squares, mean 0.48), with black triangles where that car won and a dashed line at the observed 9/14. Right: the mean Brier score at each setting. The sharper setting is better scored (0.528 vs 0.578).
Halving the pace SD moves the mean P(win) for the grid-1 car from 0.395 to 0.477, still below the 9 of 14
it achieved (Wilson 95% interval 0.388–0.837), and it improves the Brier and log scores. Two cautions. Fourteen
races is a small sample. And we chose the half setting after seeing Chapter 27's result, so treat it as
evidence the default is too wide, not as a calibrated replacement. A principled fix would give each car its
own uncertainty, smaller for cars whose qualifying-to-race link has been stable. That is Exercise E1.
Meanwhile --pace-sd-scale lets you run the sharper setting, and the HTML report tells every reader to
read front-row P(win) as a floor.
2. The uncalibrated lap simulator
Chapter 11's lap simulator, run with its preset car parameters, was slower than the real pole lap at every one of 42 circuits. The median error was +6.73 s (8.8%) in 2026, and at Las Vegas 2026 it was +6.251 s. Calibrated on real laps, the out-of-sample error fell to a median 1.38 s (1.77%), and Las Vegas came within 0.630 s in-sample. Even calibrated, 1.38 s a lap is many times the 0.258 s that separated pole from second at Las Vegas. That is why Box Box takes pace from timing data and keeps the lap simulator as an explanation tool. The lap simulator answers "why is this car fast here?". It cannot yet answer "how fast will it be on Sunday?".
⚠️ Common pitfall: trusting a physics model's absolute lap time. A lap simulator can be excellent at differences (what 10 kg or 10% more downforce is worth: Chapter 11 found a median 0.033 s per kg, matching the fuel effect) and still be seconds out in absolute terms. Use it for sensitivities, and use timing data for pace.
3. The fuel correction moves the call
Every degradation number in this book has had to say which fuel correction it uses. Box Box uses the toolkit default, which assumes 100 kg of fuel at 0.03 s per kg. Here is what happens to the winner's best stop lap when the whole pre-race degradation model is refitted on raw lap times, default-corrected ones, and ones corrected with each race's own data-driven fuel-and-evolution slope:
stint table (raw): 3262 stints; median slope by compound S 0.018, M 0.003, H -0.002
stint table (default): 3262 stints; median slope by compound S 0.064, M 0.051, H 0.048
stint table (data): 3262 stints; median slope by compound S 0.061, M 0.054, H 0.052
race fuel winner sequence actual status deg best_first clean_optimum error
2026 Las Vegas Grand Prix raw VER S-M 19 SC 0.005 / 0.005 / 0.005 37 S-H 35 -18
2026 Las Vegas Grand Prix default VER S-M 19 SC 0.045 / 0.036 / 0.017 22 S-H 15 -3
2025 Mexico City Grand Prix raw NOR S-M 34 GREEN 0.023 / 0.011 / 0.005 27 S-H 16 7
2025 Mexico City Grand Prix default NOR S-M 34 GREEN 0.061 / 0.055 / 0.043 35 S-H 30 -1
2025 Hungarian Grand Prix raw NOR M-H 31 GREEN 0.035 / 0.014 / 0.012 31 M-H 31 0
2025 Hungarian Grand Prix default NOR M-H 31 GREEN 0.083 / 0.057 / 0.059 35 M-H-H 24, 47 -4
Median |error| by fuel correction: {'data': 4.0, 'default': 3.0, 'raw': 5.5}

📊 Figure (described): For each validation race, three markers show the model's best first-stop lap for the winner's tyres under raw, default and data-driven fuel correction, with a star at the actual stop. Default and data-driven corrections land within a lap or two of each other. Raw lap times move the call by up to 19 laps (Singapore: lap 45 against 26), because the falling fuel load hides the tyre wear.
The raw version has the largest median error (5.5 laps, against 3.0 for the default and 4.0 for the data-driven correction), and it is the one you should trust least anyway. At Las Vegas and Singapore its deg collapses to the 0.005 floor for every compound, so the "optimum" is an artefact of the floor. It still happens to land on Hungary's lap 31 and the United States' lap 24, which is luck on six races, not skill. On six races the ranking of the other two means little either: the data-driven correction calls Mexico City to the lap (34) and misses Hungary by five. The real lesson is the spread. The same race, the same optimiser and three defensible fuel corrections give calls up to 19 laps apart, and they can flip the stop count: at Hungary the default correction wants two stops and raw wants one. The fuel correction is a modelling decision that changes the answer, so it has to be stated with every answer. Box Box writes it into the report's input table.
4. Pooled compound offsets
The compound check failed at Las Vegas and Mexico City for one shared reason. The offsets between
compounds (SOFT −0.136, HARD −0.039 s/lap vs MEDIUM at equal age) and the warm-up penalties are pooled
across all circuits. On those numbers the HARD is slightly faster than the MEDIUM at equal age, and it
usually wears more slowly in DegModel too, so the optimiser keeps choosing it. The teams kept not choosing it.
At Las Vegas none ran it. A circuit-specific offset model, shrunk towards the pooled values the way
DegModel shrinks deg, is the obvious next module. It is Exercise E2.
🧪 Illustrative model: the pooled compound offsets and warm-up penalties are measured (Chapter 12's paired-median values and the book's warm-up variant), but using one set for every circuit is an assumption, and the compound misses above are its cost.
🔄 Check your understanding 1. Halving the pace SD improved the Brier score. Why is that not enough to adopt 0.5 as the new default? 2. Why does the raw-lap-time version of the model sometimes land on the right lap?
Answer
1. The setting was chosen after seeing the problem (no out-of-sample test), the sample is 14 races, and a uniform scale treats every car alike, which is the real flaw. 2. Its deg estimates are often floored to the same tiny value for every compound, which makes the cost curve nearly flat. A flat curve puts the "optimum" in an arbitrary place that is sometimes, by luck, close to the real stop.
40.7 The season backtest: every dry race of 2025 and 2026
Six races make good stories but a weak statistic. code/05_season_backtest.py runs the pre-race inputs and the clean
optimum for every dry Grand Prix of 2025 and 2026. It leaves out 2025 Miami (OpenF1 is missing laps 2–24)
and races where the winner changed tyres under a red flag, a free stop no plan can schedule. That leaves 34 races:
Dry races 2025-26 without a red-flag tyre change for the winner: 34
pre-race model matches the winner's stop count 21/34 = 0.618 [0.450, 0.761]; 2025: 11/20, 2026: 10/14
hindsight model (race's own deg) matches the winner's stop count 25/34 = 0.735 [0.569, 0.854]; 2025: 15/20, 2026: 10/14
'always one stop' rule matches the winner's stop count 20/34 = 0.588 [0.422, 0.736]; 2025: 11/20, 2026: 9/14
misses: model fewer stops 10, more stops 3
One-stop winners: 20; degenerate calls 1
green-flag stop n = 13: median |error| 4.0 laps; inside the 1-s window 6/13; median signed error -1.0
stop under SC/VSC n = 6: median |error| 7.5 laps; inside the 1-s window 3/6; median signed error -7.5

📊 Figure (described): Bars for three methods (pre-race model, hindsight model on the race's own degradation, and "always one stop") in 2025 and 2026, each labelled with its count. The pre-race model (21 of 34) and the one-stop rule (20 of 34) are one race apart. The hindsight model wins in 2025 (15/20 against 11/20 for both others) and ties the pre-race model in 2026.
Three findings, all consistent with what earlier chapters measured with simpler tools:
- Pre-race, the full optimiser is barely better than the rule "one stop" at calling the stop count (21 of 34 against 20, a gap of one race with overlapping intervals). Chapter 22's retrodiction found the same pattern: its opening-stint model matched the winner's stop count 74.1% of the time and the pre-race model 55.6%, against the one-stop rule's 59.3%.
- Better inputs beat a better optimiser. Swap only the degradation for the race's own and agreement rises to 25 of 34. Everything else, including the optimiser, the pit loss and the rules, is unchanged.
- When it misses, it wants too few stops (10 of 13 misses). Chapter 12's model-vs-field test found all 19 of its misses in the same direction. Box Box inherits that bias honestly from the deg model.
For one-stop winners whose stop was not moved by a neutralisation, the median timing error is 4 laps (a median of 1 lap early), and 6 of 13 stops fall inside the 1-s window. Stops taken under an SC or VSC are off by a median 7.5 laps, early. Teams brought the stop forward to catch the cheap pit loss, exactly as the robust policy says they should.
🔄 Check your understanding 1. The pre-race model matches 21 of 34 and the "always one stop" rule 20. Does that make the model useless? 2. Why are stops under a safety car or VSC early compared with the model's best lap, rather than scattered on both sides?
Answer
1. No. The rule can only ever say "one". The model also gives the lap, the window, the cost of each alternative and the robust policy, and with better deg inputs it reaches 25 of 34, which the rule cannot. What the near-tie shows is that pre-race degradation is the weak input. 2. A neutralisation is a chance to stop at about half price. Waiting for the clean-race optimum would mean paying the full price later, so a team inside or near its window takes the cheap stop when it comes, and the window usually opens before the optimum lap.
The full table and the season-level case are in Case Study 2.
📋 Try it: Build the strategy. Pick one race from the backtest table in
code/output/05_output.txtwhere the model made fewer stops than the winner. Runpython -m boxbox validate --year Y --gp Gand read the hindsight line. Is the miss explained by the degradation input (hindsight agrees with the winner) or by something else (hindsight still disagrees)? Write one sentence for each.
40.8 Running it on the next Grand Prix
The data snapshot ends with the 2026 Las Vegas GP. The next race on the calendar is the Qatar Grand Prix
(round 22, at Lusail, Jolpica circuit_ref losail). Here is how you would get a data-informed view of
Sunday by Saturday night:
- Move the snapshot forward. In
scripts/fetch_openf1.py, setSNAPSHOT_ENDto a time after the qualifying session. Inscripts/build_jolpica.py, moveSNAPSHOT_DATEforward. - Fetch.
python scripts/fetch_openf1.pydownloads only what is missing, politely (about 30 requests a minute on OpenF1's free tier). This is the only step that touches the network. Jolpica's top-up runs insidebuild_jolpica.py. - Rebuild.
python scripts/build_jolpica.py, thenpython scripts/build_openf1.py(about a minute), thenpython scripts/data_inventory.pyto refresh the snapshot tables. - Simulate. From
project/:python -m boxbox simulate --year 2026 --gp losail.
Box Box works before the race is run. When it finds a qualifying session but no race, it switches to pre-race mode. It builds the field from the qualifying classification, takes the race distance from the circuit's last edition, and leaves each car's starting tyre for the model to choose. Two cautions are printed in that mode. Grid penalties are not applied, so check the official grid. And the gradient-boosting second opinion is skipped, because its feature table needs the race row in Jolpica.
⚠️ Common pitfall: an ambiguous
--gp.f1data.sessionmatches names by substring. In 2026, "United States" also matches Miami and Las Vegas, and in 2023 and 2025 "Qatar" needs care too. Use thecircuit_ref(americas,losail) or the round number.python -m boxbox races --year 2026lists them.📋 Try it: Predict the race. After the refresh, run
simulatefor the next race twice: once with the defaults and once with--pace-sd-scale 0.5. Write down, before the race, the clean-race optimum, the robust policy for the pole car, and the top three by P(win) under each setting. After the race, refresh again and runvalidate. Which checks passed? Which setting scored the better Brier? Keep a log; after five races you will have your own calibration study.🔄 Check your understanding 1. In pre-race mode, which two inputs does Box Box take from the qualifying session that it would otherwise take from the race's own data? 2. Why is the network touched in only one of the four refresh steps?
Answer
1. The grid (the qualifying order instead of Jolpica's starting grid with penalties) and the starting tyres (left free instead of read from the first stints). 2. Because everything else, the build and the simulator alike, reads the archive on disk. That keeps every run reproducible: the same snapshot gives the same answer, and the book's rule that chapter code never fetches holds for Box Box too.
When the season ends, the same loop rolls into the next one. Two things need attention when the rules
change. regs.rule_set and regs2026.regime read the season's rules from data/reference/, and those
tables need the new season's rows before the simulator can enforce its allocation or minimum stops. The
pre-race filter takes care of the rest. In round 1 there are no same-season races, so the adapter falls back to
the previous season for the pace link and the DNF rates and says so in the report.
40.9 Closing the book
The themes, one last time
We started with six ideas. Box Box is what they look like as running code.
- F1 is an optimization problem. The clean-race optimum is an exhaustive search over every legal plan. The robust strategy is an optimization under uncertainty with 21 adversaries. Both live in one command.
- Tyres are everything. Every validation miss in 40.5 came back to tyres: a compound mispriced, a degradation rate outside history, a set extended for track position. Fix the tyre inputs (the hindsight model) and agreement rises from 21 to 25 of 34.
- Data doesn't replace instinct; it sharpens it. The model's window at Singapore was laps 20–31. Verstappen's team went to 32 and won. The model did not overrule that call. It priced it at about a second and showed it was cheap.
- The margins are impossibly small. Inside a 1-s window, the choice of lap is worth less than the gap between two cars in clean air. Outside it, a stop decision is worth more than a qualifying slot.
- Every lap is a dataset. Box Box needs no team data at all. It runs on 268,783 laps of free timing, and it can be rerun by anyone with a laptop.
- The sport is the engineering as much as the racing. The simulator's biggest lever is pace from the car, which we measure from timing because the physics model is not yet accurate enough. The engineering chapters explain the car. The timing data measure it.
The four anchors, and how they came out
- Anchor A, the speed trace. At Suzuka in 2025, Verstappen's pole lap of 1:26.983 beat Norris's 1:26.995 by 0.012 s. The story we were handed had Verstappen on the throttle 15 m earlier at the Casio Triangle. The data said the opposite: Norris reached full throttle 19 m earlier there, with samples about 11 m apart, yet Verstappen gained 0.089 s in that final segment. The two laps traded time all the way round. The lesson was the resolution of 3.7 Hz telemetry, not a hero's throttle foot.
- Anchor B, the degradation model calls the stop. At the 2025 Mexico City GP, Norris stopped after lap 34. The model, on the race's early stints, said lap 36, inside a flat window of laps 33–40. On practice long runs it said lap 41. The median error across 16 model runs was 4 laps. Box Box, on pre-race inputs only, says lap 35 (window 31–39), one lap earlier because history expected a little more SOFT wear than the race showed; given the race-stint inputs it returns lap 36 exactly. Both windows hold the actual stop, and the season backtest confirms the moral: the inputs matter more than the optimiser.
- Anchor C, the safety-car gamble. Across 10,000 simulated Singapore races, a planned two-stop was 10.10 s slower on average and better in only 18.9% of runs (Chapter 27). The robust answer was a flexible one-stop, worth 0.84 s. In 2026 Singapore, Leclerc and Antonelli took the cheap second stop under the lap-39 VSC and finished second and third, behind Verstappen's one-stop. The "65% safety-car probability" of Singapore folklore turned out to be one SC in four recent races.
- Anchor D, the teammate chain. Through the shared-teammate network, Verstappen − Hamilton came out at −0.230% of a qualifying lap, with a 95% interval of −0.408 to −0.069. The verdict: the chain leans Verstappen by about 0.1–0.3%, the direction is robust, and the size depends on the method. It is not settled, and it was never going to be.
In all four, the data told a different story from the one we started with, and the book told the data's story. That is the promise of the first page kept.
Sector Four signs off
The five of them met on the call the night after Las Vegas, as they had after most races for a year and a half.
Ines went first, as she always did. "I'll do it myself this time. Why did they pit on lap 19?" She answered her own question: "Because the safety car made the stop cost about twelve seconds instead of twenty-three, and they were all inside the window anyway." Nobody had to add anything.
Tom had brought the Formula Student car's first test data, logged by the team's own sensors at a
far higher rate than the OpenF1 feed. He had run his team's corner speeds through physics.max_corner_speed and found the
downforce figure in their design report was optimistic. "Same lesson as Chapter 11," he said. "Calibrate
first, believe second."
Kenji had spent the week in his sim league with telemetry_tools.compare_laps, and had stopped asking
where he was slow. "It tells me what kind of slow. Braking or exit. Mostly exit."
Ray had not placed a bet on Las Vegas. "Your simulator said Verstappen one in five. The base rate for pole said three in five. When the model and the base rate disagree that much, I don't bet the model. I fix it." He had already written down the half-SD setting as his first test for Qatar.
Aisha pushed the last commit: cli.py, report.py and the tests, 55 of them, all passing. She
pinned the Las Vegas report to the top of the group's page and wrote one line under it: It got the stops
right, the tyre wrong and the winner's odds too low. Now we know what to build next.
Where to go next
- Improve Box Box. The exercises in Part E are the next modules: per-car pace uncertainty,
circuit-specific compound offsets, an allocation tracker that reads each driver's sets from qualifying,
and a wet-tyre branch for the race engine using
wetandconditions. - Go deeper into the methods. Heilmeier et al. (2020) on Monte Carlo race simulation and on a neural
"virtual strategy engineer", and Bekker & Lotz (2009) on discrete-event race-strategy simulation, are the
closest published relatives of Box Box (see
further-reading.md). - Look outward. Chapter 39 showed that the
same machinery prices refuelling, cautions and stages.
series.RuleProfileis the starting point for pointing Box Box at another championship. - Use the official data route if you have it. FastF1 with an F1 TV subscription gives richer timing (Appendix J). Everything in this book still runs on the free sources.
- Contribute. The book and Box Box are CC-BY-SA-4.0. Rerun a chapter on a new race and fix a number that has drifted, or send a better module.
🪞 Learning check-in Look back at the Chapter 1 question "what makes an F1 car fast?" and at the Chapter 12 question "why did they pit?". Write your answer to each in three sentences, now, without looking anything up. Then answer a third: which one number in a Box Box report would you check first before trusting it, and why? If your answer to the third is "the degradation input and its fuel correction", the book has done its job.
Spaced Review
Three questions from earlier chapters, each one now a line of Box Box's output. Answer each before you open the answer.
- Chapter 12. The break-even for an extra stop is the pit loss divided by the fresh-tyre gain. With the book's median fresh-tyre delta of 1.078 s/lap and Las Vegas's pre-race pit loss of 23.39 s, how many laps must a fresh set run to repay a stop? Does that make the two-stop in 40.4 look sensible?
- Chapter 14. Under a safety car the pit loss falls to about 12.7 s (the near-field measure). At Las Vegas, 16 of the 20 cars that stopped made their first stop on the SC lap. Why did almost nobody stop twice, if a stop under the safety car was so cheap?
- Chapter 22. Why does
DegModelshrink a circuit towards the compound mean, and what did that shrinkage cost at Barcelona 2026?
Answers
- 23.39 / 1.078 ≈ 21.7 laps. A 50-lap race split into three stints gives each stint about 17 laps, so a second stop's fresh tyres never repay it in a clean race. That is why the clock-only two-stop loses 14.0 s.
- There was only one cheap moment. A car that stopped under the lap-19 SC still had 31 laps to run, and a second stop later would have been at the green-flag price for a stint its tyres could already cover. The option to stop again only pays when a second neutralisation falls late enough, which is what the flexible policy waits for, and at Las Vegas none came.
- Shrinkage protects against noisy circuit estimates (Chapter 22 chose κ = 4 on a hold-out fold). It pulled Barcelona's 2026 prediction (0.067 / 0.058 / 0.050 s/lap) towards history, while the race ran at 0.237 / 0.182 / 0.124. The model could not call three stops. Shrinkage buys stability at the price of missing genuine outliers.
Project Checkpoint: cli.py, report.py and project/tests/
This is the last checkpoint, and Aisha's last commit. Three files finish Box Box.
cli.py, the command line and the adapter. main() parses three commands (simulate, validate and
races) and calls the adapter functions in pipeline order:
| Function | Pipeline step | What it does |
|---|---|---|
resolve_race(year, gp) |
1 | finds the race (or, before it is run, its qualifying session) |
quali_to_race(year, before_round) |
2 | the season's qualifying → race pace link (Chapter 27) |
build_inputs(ctx) |
2, 4, 6 | every input, from races before this one |
clean_optimum(I, ...) |
3, 6 | Chapter 12's optimiser under the rules, each plan checked by regs |
race_setup(I) / ghost_compare(I) |
4 | the field engine (with passing calibration) and the clock-only engine |
simulate(ctx, ...) |
2–6 | the whole run; returns every table |
gbm_probabilities(ctx) |
5 | Chapter 26's model, trained on earlier seasons |
actual_strategies(session) |
validation | real strategies with phantom stints dropped |
hindsight_optimum(ctx, I) |
validation | the optimum on the race's own deg (labelled hindsight) |
validate(sim) |
validation | the three checks, the scores and the reasons |
report.py, the HTML report. write_report(sim, validation, path) writes one self-contained file with
the charts embedded. The five chart builders (strategy_figure, probability_figure, position_figure,
ghost_figure, curve_figure) are public, so the chapter scripts save exactly the figures the report
shows. The report's last section, "What this model cannot see", is not optional: it lists the missing
channels, the dry-only engine, the pole-sitter bias and the fuel-correction assumption every time.
project/tests/test_boxbox.py, the smoke tests. These are 55 tests on the real data. Every module
imports and has a docstring. The CLI parses its arguments, and python -m boxbox runs as a subprocess. The
race resolver works by key, round and name. At the 2025 Canadian GP no zero-length stint is left to drop, and the adapter's same-set merge only ever removes stops, never adds one.
The inputs use only earlier races, and the optimum is legal and sorted. The probabilities are coherent
(P(win) sums to 1, P(podium) to 3). The ghost reference is exactly zero. The report writes valid HTML. And
validate gives Box Box's pre-race Anchor B call: best lap 35 for Norris's tyres, window 31–39, actual 34.
The checkpoint script drives the finished tool exactly as you would:
$ python -m boxbox simulate --year 2026 --gp vegas --sims 2000 --compare-sims 1000 --out ...\code\output\cli_vegas (exit 0, 55 s)
=== robust strategy for VER (1,000 races per policy, same races) ===
policy mean_pos median_pos p_win p_podium p_points exp_points d_time_vs_ref p_better_pos p_worse_pos mean_stops
one-stop 5.787 3.0 0.237 0.512 0.829 13.351 0.000 0.000 0.000 0.950
two-stop 6.972 5.0 0.109 0.333 0.805 10.099 13.401 0.049 0.515 1.908
flexible 5.701 3.0 0.246 0.536 0.828 13.601 -0.896 0.047 0.014 1.240
robust (highest expected points): flexible
Files written: ['field_probabilities.csv', 'report.html', 'result.json']
$ python -m pytest tests -q -p no:cacheprovider (exit 0, 108 s)
....................................................... [100%]
With 1,000 races per policy instead of 5,000, the probabilities move in the second decimal place:
Verstappen's one-stop P(win) is 0.237 here against 0.197 in the full run. The ranking of the policies does
not move. That is the Monte Carlo standard error at work (Chapter 27), and it is why the defaults are 10,000
field races and 5,000 per policy. The full Las Vegas report is at images/ch40-report-2026-vegas.html.
🔄 Check your understanding 1. Which smoke test would fail if someone "fixed"
build_inputsto use the book-wide hazard constant and the full incident library? 2. Why doesreport.pybuild its charts with public functions instead of private ones?Answer
1.test_inputs_use_only_earlier_races, which checks that the incident library holds exactly the races before the simulated one. 2. So the chapter scripts, the report and any reader's own notebook draw the same figure from the same function. One definition per chart is the same principle the toolkit applies to metrics.
Chapter Summary
| Box Box output | Built from | What the 2025–26 validation says |
|---|---|---|
| Clean-race optimum | strategy.optimise on DegModel deg (default fuel correction), latest-edition pit loss, regs |
stop count matches the winner in 21 of 34 dry races, one more than "always one stop" (20); 25 of 34 with the race's own deg |
| Stop timing for given tyres | the same model, with the winner's compounds and start age | inside the 1-s window for 6 of 13 green-flag one-stop winners; median error 4 laps |
| Robust policy | montecarlo.compare_strategies (common random numbers) |
flexible at Las Vegas, Singapore and the United States: the option beats the commitment |
| Clock-only comparison | montecarlo.ghost_setup (Anchor C) |
planned two-stop +14.0 s at Las Vegas; flexible −0.79 s |
| P(win), P(podium) | the field engine | under-confident at the front: mean P(win) for the grid-1 car 0.395, against 9 wins in 14 races (2026) |
| Second opinion | predict (gradient boosting) |
higher P(win) for the winner in 4 of 6 validation races |
| Formula | Reading | Worked number |
|---|---|---|
| $s^* \approx \dfrac{d_2 N - d_1 a_0 + o_2 - o_1}{d_1 + d_2}$ | one-stop optimum of the linear stint model | Las Vegas, VER's S(3 laps)-M: 22.2 → lap 22 |
| break-even laps $= P / \Delta$ | laps a fresh set needs to repay a stop | 23.39 / 1.078 ≈ 21.7 |
| Brier $= \sum_i (p_i - y_i)^2$ | per race, summed over the field (lower is better) | Las Vegas 2026: 0.777 simulator, 0.149 GBM |
Decision checklist before you trust a Box Box report
- [ ] Which fuel correction do the deg numbers use? (Default = an assumed 100 kg × 0.03 s/kg.)
- [ ] Is the pit-loss pool from the current pit lane (the latest edition), and is n at least 10?
- [ ] Is the race dry? The engine has no wet tyres, so read the rain row as a hazard sensitivity only.
- [ ] Did the model choose a compound the teams are unlikely to run? Check the compound's use at the circuit.
- [ ] Read front-row P(win) as a floor. Compare it with the gradient-boosting opinion and the pole base rate.
- [ ] For a race not yet run: are grid penalties applied? (Pre-race mode uses the qualifying order.)
- [ ] Is the optimum's 1-s window wide? If so, the lap matters less than the trigger: traffic, an undercut, a safety car.
The last lap
Box Box will be wrong on Sunday. It will be wrong about a compound, or a lap, or a winner, and when it is, it will print the reason it thinks it was wrong. That is the point. A strategy model is a set of assumptions you can see, test and change. Every number in this book came from timing data you can download free, and every chart can be redrawn with one command. The simulator is the sum of those chapters, and like them it is honest about its limits.
The next race is on the calendar. Refresh the data after qualifying, run the simulator, and write down what it says before the lights go out. Then watch, and find out what the model could not see.