Chapter 27 Exercises — Monte Carlo Race Simulation

Difficulty: ⭐ concept check · ⭐⭐ calculation or short code · ⭐⭐⭐ multi-step analysis · ⭐⭐⭐⭐ open-ended project

All code exercises run offline from the book's data snapshot. Start from the chapter's scripts in code/ and the module project/boxbox/montecarlo.py. Where an answer is given, it comes from the chapter's own runs (seed 42 unless stated); if you change a seed or an input, your numbers will differ, and the exercise says what shape to expect.


Part A — Concepts ⭐

A1. Explain the difference between Monte Carlo error and model error in a race simulation. Which one does running 100,000 races instead of 10,000 reduce?

Answer

Monte Carlo error is the sampling error of estimating the model's expectation from a finite number of simulated races; it falls as 1/√n. Model error is the gap between the simulated world and the real one (wrong degradation, wrong hazard, wrong pass model). More runs reduce only the first.

A2. Why does the engine race every strategy through the same simulated races? Give the name of the technique and the size of the gain the chapter measured for the flexible-vs-one-stop comparison at Singapore.

Answer

Common random numbers: the race-to-race variation (number and timing of safety cars, stop-loss draws) cancels in the paired difference. The paired standard error was 0.084 s against 3.311 s for independent runs, about 1,560 times fewer races for the same precision.

A3. The Bellman table is built from the point estimates of degradation, but each simulated race is scored with degradation drawn from its sampling distribution. Why is that the right design for a strategy tool?

Answer

A strategist decides with a model, not with the truth. Deciding with the point estimates and scoring with draws measures what the decision rule is worth when the model is wrong in the ways it plausibly is. Deciding with the draws would give simulated cars information no team has.

A4. In ghost mode the flexible strategy's median gain over the one-stop is exactly 0, but its mean gain is 0.84 s. Explain, and say why the common advice to "pick the strategy with the best median" would mislead here.

Answer

In 78.7% of simulated races no neutralisation made a second stop pay, so the flexible car ran the identical race: the median difference is 0. In the remaining races it was better 15.5% of the time and worse 5.8%. The median ignores exactly the races where the option matters; the mean and P(better)/P(worse) reveal it.

A5. What does "ghost mode" switch off, and which one of those switches made the biggest difference to the two-stop's time cost when the chapter moved to field mode?

Answer

Traffic and passing, lap-1 shuffles, gap compression under SC, lap noise and retirements; and the cars share every random draw. Moving to the field, the two-stop's cost grew from about 10 s to 24–26 s at the front, mostly traffic: after each extra stop the car rejoins behind slower cars at a circuit where passing needs a large pace advantage.

A6. Why must the fuel term in the lap-time equation be "paired" with the degradation input? What fuel term goes with degradation fitted at the toolkit default (100 kg, 0.03 s/kg) in a 56-lap race?

Answer

The default correction adds 3.0/N s/lap to each raw stint slope (it removes a fuel effect of 3.0/N per lap). If the engine then adds no fuel term, laps get slower through the race by the fuel effect that was removed; if it adds a different one, the effect is double-counted or lost. For N = 56: f = −3.0/56 = −0.054 s/lap.

A7. The engine draws each stop's loss from a pool of real stops rather than using the median. At Singapore 2025–26 the pool's median is 23.866 s and its mean 24.993 s. Which strategy does the pool penalise more, and by roughly how much per extra stop?

Answer

The strategy with more stops: each extra green stop costs on average about 1.1 s more than a median-based model expects (24.993 − 23.866). That is why the no-incident races in the main run show the two-stop 11.6 s behind rather than the clean-race 10.4 s.

A8. What is a PIT value, and what should a histogram of PIT values look like if a finishing-position forecast is calibrated?

Answer

For each driver, the forecast probability of finishing ahead of his actual position plus half the probability of finishing exactly there. Across many drivers and races, a calibrated forecast gives PIT values spread uniformly between 0 and 1: a flat histogram. A U shape means over-confidence; a hump in the middle means under-confidence.


Part B — Calculations & Physics ⭐⭐

B1. Retirement hazard. A team's cars retire in 22% of races in your model (after lap 1). The race has 57 laps. What constant per-lap hazard reproduces that, and what is the probability that a car is still running after lap 30?

Solution

h = −ln(1 − 0.22)/(57 − 1) = 0.2485/56 = 0.00444 per lap.

Survival after lap 30, i.e. through laps 2–30 (29 laps at risk): e^(−29 × 0.00444) = e^(−0.1287) = 0.879. So 12.1% have retired by then.

B2. Runs needed. In a paired comparison, the per-race SD of the time difference between two strategies is 6.40 s (the chapter's flexible-vs-one-stop SD at Singapore). How many races do you need for a 95% interval of ±0.25 s? Of ±0.1 s?

Solution

n = (1.96 × 6.40 / h)². For h = 0.25: (50.18)² = 2,518 races. For h = 0.1: (125.4)² = 15,735. (The chapter's script prints 2,515 and 15,717 with the unrounded SD.)

B3. A probability's error. Your simulation says P(two-stop faster) = 0.19 after 1,000 races. What is the standard error, and how many races do you need to know it to ±0.5 percentage points at 95%?

Solution

SE = √(0.19 × 0.81 / 1000) = 0.0124 (1.24 points). For a half-width of 0.005: n = 1.96² × 0.19 × 0.81 / 0.005² = 23,650 races.

B4. Critical degradation. Use Chapter 12's formula $d^* = 2(k+1)(k+2)P/N^2$ for the first extra stop (k = 1) at Singapore (P = 23.866 s, N = 62) and at Austin with the chapter's validation inputs (P = 21.124 s, N = 56). Compare each with the degradation the simulation used. Which race is closer to two stops?

Solution

Singapore: 12 × 23.866 / 3,844 = 0.0745 s/lap, against FE wear of 0.032–0.052: well below, so one stop.

Austin: 12 × 21.124 / 3,136 = 0.0808 s/lap, against the pre-race DegModel's 0.043–0.055: one stop. But the race's own default-corrected wear was 0.081 (SOFT, MEDIUM) and 0.057 (HARD), right at the line. That is why 9 of 19 finishers two-stopped, and why the pre-race simulation (10% two-stoppers) missed.

B5. Safety-car compression. The engine shrinks each gap $g$ above 0.44 s to $0.44 + 0.61(g - 0.44)$ per SC lap. Two cars are 12.0 s apart when a 4-lap safety car begins. What is the gap at the restart? What fraction of the original excess gap survives?

Solution

Excess over the floor: 11.56 s. After 4 laps: 11.56 × 0.61⁴ = 11.56 × 0.1385 = 1.60 s, so the gap is 0.44 + 1.60 = 2.04 s. About 14% of the excess survives, which is how the factor was chosen (Chapter 14 measured a leader-to-P10 ratio of 0.14 across safety cars).

B6. The VSC price. At the 2026 Singapore lap-39 VSC, the decision table gave Leclerc's MEDIUM (14 laps old) a "stay" cost of 24.94 s and a "go" cost of 6.06 s for laps 40–62. At what VSC stop price is he indifferent? Compare with the model's price (18.40 s) and the price he actually paid (12.48 s).

Solution

Indifferent when price = 24.94 − 6.06 = 18.88 s. The model's 18.40 s is just below that (pit, margin +0.48 s). The 12.48 s he actually paid gives a margin of +6.40 s. The time case for the stop was marginal at model prices and clear at the real price; track position is a separate question (Case Study 1).

B7. Mean vs median of a ratio. The trimmed SC ratio pool has a median of 0.639 and a mean of 0.688. The decision model plans with 0.632, Chapter 14's field median. With a 23.866 s green stop, how much more does an SC stop cost on average than the decision model expects? How does that bias a model that plans with a median?

Solution

23.866 × (0.688 − 0.632) = 1.34 s per SC stop. A model planning with a median expects SC stops to be cheaper than they are on average, so it takes slightly too many of them. In the chapter's ladder, switching from fixed (median) ratios to drawn ratios raised the two-stop's mean cost by about 0.6 s.

B8. Hazard to probability. With the book's phase hazards (lap 1 0.1758; laps 2–10 0.0309; middle 0.0186; final 10 0.0149) and k = 0.69, compute P(at least one incident) in a 56-lap race, assuming every lap is at risk.

Solution

Sum of hazards: 0.1758 + 9 × 0.0309 + 36 × 0.0186 + 10 × 0.0149 = 0.1758 + 0.2781 + 0.6696 + 0.149 = 1.2725. Times k: 0.878. P = 1 − e^(−0.878) = 0.584. The validation script prints 0.58 for Austin.


Part C — Data & Code ⭐⭐–⭐⭐⭐

C1. Analyze this session: the engine's ingredients at another circuit. ⭐⭐

Run 01_engine_ingredients.py, then compute the circuit multiplier $k$ for Monza (nz.circuit_multiplier("monza", nz.HAZARD_2023_26, S)), and P(≥ 1 incident) for a 53-lap Monza race. Compare with Singapore's 0.84.

Expected shape: Chapter 14 reported Monza's pooled k = 0.75 (0.44–1.20). P(≥ 1 incident) should come out well below Singapore's, around 0.6.

C2. Build the strategy: Anchor C at a second circuit. ⭐⭐⭐

Adapt _common.singapore_inputs() to the 2023–26 races of the Hungarian Grand Prix (circuit_ref = "hungaroring"). Fit the fixed-effects tyre model, take the green stop pool, compute k, and run the ghost comparison of one-stop, two-stop and flexible with 10,000 races.

Expected shape: a print of the FE deg/offset table, the clean-race plans and gap, and the ladder's main line (E[two − one], P(two better), E[flex − one]). Hungary's wear is higher than Singapore's (the book's circuit table has HARD at 0.076 s/lap, default fuel), so check its critical degradation before you run. Does the two-stop come closer? Does the answer flip?

C3. Compare these drivers: focal cars in field mode. ⭐⭐⭐

Using 04_singapore_field.py, run compare_strategies for Norris (grid 5) and Lawson (grid 8). Report E[position], P(points), P(better) and P(worse) for one-stop, two-stop and flexible.

Expected shape: a 6-row table like the chapter's. Based on Section 27.6, predict before you run: should the flexible option help Lawson more than Norris? Then check.

C4. Convergence for a probability. ⭐⭐

In 03_convergence.py, add the running estimate of Verstappen's P(win) from a field-mode run of 10,000 races (one-stop policy). Plot it with its ±1.96 SE band on a log axis, as in Figure 27.6.

Expected shape: the main field run gives P(win) = 0.518. The band should be about ±0.03 at n = 1,000 and ±0.01 at n = 10,000.

C5. Analyze this session: replay a real race. ⭐⭐⭐

Use Car.plan to replay the 2025 Mexico City Grand Prix (the book's Anchor B race) with every car on its real strategy, from f1data.stints. Force the real neutralisation timeline (nz.lap_status) and build the setup with _common.race_setup(2025, 20, pace_source="race"). Simulate 5,000 races. What share of them reproduce the real winner? The real podium?

Expected shape: one line per statistic. This is a test of the engine given strategies and timeline; if the winner share is low, look at the pace gaps and the pass threshold before blaming the tyres.

C6. Predict the race: a different 2026 race from its grid. ⭐⭐⭐

Run the validation recipe (06_validation_usgp.py) on the 2026 Austrian Grand Prix (round 8). Report P(win) and P(podium) for the top six on the grid, the Brier scores against the grid base rate, the 10–90% coverage and the simulated share of two-stoppers.

Expected shape: the same tables as Section 27.8. Case Study 2 ran this race inside its season loop: the simulated P(win) of the winner (Russell, from pole) was 0.377, and the simulated mean stops per finisher was 2.13 against a real 2.17. Austria is one of the few races where the pre-race wear model got the stop count right.

C7. Decision rule: plan with the mean, not the median. ⭐⭐⭐

RaceSetup.decide_ratio sets the SC/VSC ratios the decision table uses. Re-run the ghost Anchor C (step C of the ladder) with decide_ratio={"SC": 0.688, "VSC": 0.857}, the means of the trimmed pools. How do E[flex − one] and P(flex worse) change? Then repeat the tornado's "every incident a VSC" row with mean-based decisions.

Expected shape: two short tables. You should find that deciding with the mean cuts the flexible strategy's bad stops, especially in the all-VSC case, where the median-based rule made the option worthless.

C8. Calibration by grid slot. ⭐⭐⭐

Using code/_calibration_2026.csv (written by case_study_02.py), group driver-races by grid slot (1, 2–3, 4–6, 7–10, 11+) and compare the mean simulated P(win) and P(podium) with the observed shares.

Expected shape: a 5-row table. Case Study 2 found the pole-sitter's mean simulated P(win) was 0.39 against 10 wins in 15 races. Is the under-confidence confined to pole, or does it extend to the front row?


Part D — Strategy & Judgment ⭐⭐⭐

D1. Call the pit stop: 2026 Singapore, lap 8, VSC. The first VSC of the 2026 Singapore Grand Prix came on lap 8 (race control, leader's lap). Verstappen and Leclerc started on SOFTs (Leclerc's 3 laps old). There are 54 laps to go, and the MEDIUM's stint cap at Singapore is 43 laps. Before running anything, decide: should a car on the model's one-stop plan (SOFT, stop after lap 36) take its stop now? Then use decision_table (Singapore FE tyres, flexible policy, VSC price 18.40 s) to check your call.

Discussion

Stopping at lap 8 leaves 54 laps, more than any single dry compound's cap (SOFT 37, MEDIUM 43, HARD 47). The car would need a second stop later, so a VSC stop here commits it to a two-stop race, which the clean-race model prices at about 10 s more than the one-stop. Expect the table to say "stay out" for both. In the real race nobody in the top six stopped on lap 8.

D2. Design the setup: the engine for a team. You have the engine and one week before the next race. List, in order, the three inputs you would spend the week improving, and justify the order with this chapter's tornado (Section 27.7) and validation (Section 27.8).

Discussion

A defensible order: (1) degradation for this circuit and this year's tyres, the input that dominated both the tornado and the validation miss; (2) the pit-loss pool for the current pit-lane rules, the other dominant tornado input; (3) the pass model, which flipped the field-mode verdict on the flexible option. The hazard multiplier comes after these. It matters, but within its uncertainty it moved the answer by about 1.4 s.

D3. Mean or win probability? You are the strategist for the car on pole at Singapore (the chapter's Verstappen case). In field mode your simulation says the flexible option loses 0.21 s of race time and 0.27 expected points against the one-stop, and changes the win probability from 0.517 to 0.511. A board member asks for "the strategy with the best chance of winning". Is there any version of this question for which you would choose the flexible option? Argue both sides.

Discussion

On these numbers the one-stop is better on every summary: mean position, P(win) and expected points. The case for flexibility rests on the model's weakest component: the pass model probably makes passing on fresh tyres too hard (Leclerc passed Hamilton within six laps in the real race). If you believe passing is easier than the calibration implies (Section 27.6: the sign flips near a 1.5 s/lap threshold), the option is worth a little. The honest answer is "keep the option, but take the extra stop only if it does not cost track position to a car you cannot pass." That is a position-aware rule, and the time-only table does not implement it (Part E).

D4. The folklore. A commentator says, "At Singapore you always plan two stops because the safety car is guaranteed." Write a 150-word reply using three numbers from this chapter.

Model answer

Three numbers do it. First, a neutralisation is likely, not guaranteed: the book's hazard model gives 84% for any SC, VSC or red flag, and race control shows only one full safety car in the four Singapore races of 2023–26. Second, even with a neutralisation, a planned two-stop loses: across 10,000 simulated races it is 10.1 s slower on average and faster in only 19%, and no hazard up to three times Singapore's estimate flips that. Third, the value lies in the option: a one-stop that takes a second stop only when a safety car makes it pay gains 0.84 s against the clock. Against real rivals at Singapore, where passing is hard, even that option is close to neutral at the front of the grid.


Part M — Mixed / Interleaved ⭐⭐–⭐⭐⭐

M1. (Chapters 12 and 27) ⭐⭐. Chapter 12's optimiser and this chapter's Bellman table both find the clean-race optimum. Show that for Singapore they give the same one-stop cost difference (+10.38 s for the two-stop), and explain why the Bellman table also handles a neutralisation on lap 20 without re-optimising.

Answer

Both minimise the same linear stint cost, so the clean-race optimum and its cost coincide; the chapter's script prints +10.38 s. The table stores the optimal continuation from every state (lap, compound, age, stops left, compound rule satisfied). By the principle of optimality, the best decision at a lap-20 safety car is "price + GO vs STAY" at that state, and that is already in the table.

M2. (Chapters 14 and 27) ⭐⭐. Chapter 14's near-field pit loss under an SC is 12.722 s; this chapter's field-relative ratio is 0.639 (median). Using Singapore's 23.866 s green stop, compute each version's SC stop cost. Which is more conservative, and which did the Anchor C model use?

Answer

Near-field: about 12.7 s pooled (Chapter 14's near-field ratio of 0.547 × 23.866 = 13.05 s at Singapore). Field-relative: 0.639 × 23.866 = 15.25 s at the median. The field-relative version is more conservative (it makes SC stops dearer), and Anchor C used it, drawing the ratio per stop from the trimmed pool.

M3. (Chapters 17 and 27) ⭐⭐⭐. The engine links the lap-1 incident probability to lap-1 retirements (12 of 21 races with a lap-1 retirement had a lap-1 neutralisation, against 4 of 70 without). Switch the link off (lap1_link=False) in the USGP validation setup and compare the simulated share of races with a lap-1 incident and the pole-sitter's P(win). Explain the direction of any change.

What to expect

Without the link, the lap-1 incident probability is the unconditional k × 0.176 regardless of what happened on the grid. The overall share of lap-1 incidents should be similar, but they no longer coincide with the starts that already scrambled the order. Any change to the pole-sitter's P(win) is small; the exercise is about whether events that should be correlated are.

M4. (Chapters 20, 22 and 27) ⭐⭐⭐. The validation used qualifying-based pace with a 0.53 s/lap uncertainty, and the season study found the engine under-confident about pole-sitters. Re-run the 2026 USGP with pace_sd=False (no pace uncertainty), then with half of it. Compare the Brier scores for win and podium with the main run's.

What to expect

Less pace uncertainty makes the forecasts sharper: Antonelli's P(win) from pole should rise towards the grid base rate. Whether the Brier scores improve depends on whether the sharper forecast is right. On one race you cannot tell; run it across Case Study 2's 15 races before concluding.

M5. (Chapters 13 and 27) ⭐⭐⭐. Chapter 13 measured undercut success at 42.9% when the attacker is within 3 s. In the field-mode engine, count how often a car that pits one lap before the car directly ahead of it finishes ahead of that car. Compare with Chapter 13's rate.

What to expect

You need keep_laps=True and the per-car stop laps. Expect the engine's undercut to work more often than Chapter 13's 42.9% at short gaps: rivals in the engine never "cover" by pitting on the next lap unless their own table says so.


Part E — Research & Extension ⭐⭐⭐⭐

E1. A position-aware decision rule. The time-only Bellman table makes the flexible option cost places at the front at Singapore. Design and implement a rule that takes an extra stop under SC/VSC only when it pays in time and the car will not rejoin behind a car it is unlikely to pass. For example: use the gap to the car behind and the engine's pass model. Run it through the chapter's field comparison and report whether the option's value becomes positive at the front. Discuss whether your rule is something a pit wall could actually compute in the seconds after a deployment.

E2. Learn the pass model from data. Using the OpenF1 green on-track overtake filter (Chapter 35's definition), estimate a pass probability as a function of pace advantage and tyre-age difference. Replace the engine's logistic with your fitted curve, re-run Section 27.6, and report which conclusions change. Pay attention to how your fitted curve treats passes of a car having an error lap.

E3. A season-long calibration report. Extend Case Study 2 into a full validation report for the engine: all dry 2026 races, reliability diagrams for win, podium and points, PIT histograms by grid slot, and a comparison against three baselines (grid order, the pole-wins rule, and Chapter 26's prediction model, if available). Recommend which inputs to change, and test your recommendation on 2025 races without looking at the 2026 results again.