Chapter 40 Exercises — Capstone: Your F1 Race Strategy Simulator

Difficulty: ⭐ concepts · ⭐⭐ calculation or a short script · ⭐⭐⭐ analysis and judgment · ⭐⭐⭐⭐ open research.

All code runs offline from project/ (for python -m boxbox …) or from the chapter directory (for the scripts in code/). Where an answer is a number, it comes from the chapter's own runs. Your numbers may differ in the last decimal place if you change the seed or the number of simulated races.


Part A — Concepts ⭐

A1. In one sentence each, say what these Box Box outputs are for: the clean-race optimum, the robust policy, the clock-only comparison, the outcome distribution and the gradient-boosting second opinion.

A2. The adapter cuts every input table at the race's start time. Name four inputs that are cut this way, and the two inputs taken from the race itself. Explain why those two are allowed.

A3. What is a phantom stint in OpenF1? Why does it inflate stop counts, and how does cli.actual_strategies remove it?

A4. Why did Box Box's pit loss for the 2026 Singapore GP come from 2025 alone, and not from all four years of Singapore data? What would have gone wrong with the larger pool?

A5. validate checks stops, timing and compounds separately. For each check, give one race from the chapter where it failed, and the reason.

A6. Explain in plain English why the flexible policy can beat the one-stop in the clock-only runs and still finish behind it in some field races.

A7. The simulator gave the 2026 Las Vegas pole car 20.9% to win. The gradient-boosting model gave it 65.9%. What does each model "see" that the other does not?

A8. Why does Box Box not use Chapter 11's lap simulator to set race pace?

A9. "The fuel correction is a modelling decision that changes the answer." Give the evidence from 40.6 in two sentences.

A10. In pre-race mode (a race not yet run), which two cautions does Box Box print, and why?

Answers to Part A

A1. The clean-race optimum is the plan to start from if nothing happens. The robust policy is the plan that does best across the races that might happen. The clock-only comparison isolates what a strategy is worth in time, with traffic and rivals removed. The outcome distribution says what the race might look like for every car. The gradient-boosting model is an independent forecast built on history, used to check the engine's probabilities.

A2. Cut at the start time: the degradation model, the stint caps, the pit-loss pool, the hazard and circuit multiplier, the incident library, the SC/VSC ratio pools, the pass counts and the DNF rates (any four). Taken from the race: the starting grid (Jolpica, penalties applied) and the starting tyres (each car's first stint). Both are public when the lights go out, so using them leaks nothing.

A3. A stint whose last lap comes before its first, inserted when a car passes through the pit lane on the same set. strategy.actual_strategies sees a stint boundary and counts a stop. The adapter drops stints with lap_end < lap_start, then merges stints that continue the same set (same compound, start age within 2 laps of where the previous stint ended).

A4. Singapore's pit-lane limit rose from 60 to 80 km/h in 2025, and its green loss fell from about 29.7 s to 23.2 s. A pool of the three earlier years (2023–25) has a median of 29.15 s, which would overprice every stop by about 5 s and make any multi-stop plan look worse than it was.

A5. Stops failed at Hungary 2025 (the model wanted two, Norris made one; the compounds check passed there). Timing alone failed at Singapore 2026 (Verstappen extended one lap past the window). Compounds alone failed at Mexico City 2025 and Las Vegas 2026 (the model preferred HARD). Barcelona 2026 failed all three.

A6. In the clock-only runs, the flexible car only stops again when a neutralisation makes it pay, so it cannot lose time to the one-stop except through bad luck on the stop draws. In the field, a second stop can drop the car into traffic where the time cannot be recovered, and can cost places that the clock does not count.

A7. The simulator sees measured pace (the qualifying gap times the season's race link) with a wide uncertainty, so it rated Antonelli's faster lap highly despite his sixth place on the grid. The gradient-boosting model sees history: grid slot, form and standings. In its training data the pole-sitter wins more than half the time.

A8. Out of the box it was slower than real pole laps at every one of 42 circuits (median +6.73 s in 2026). Even calibrated, its out-of-sample error (a median 1.38 s) is several times the gaps that decide grid order. Timing data measure pace directly.

A9. Refitting the pre-race degradation on raw, default-corrected and data-corrected lap times moved the winner's best stop lap by up to 19 laps (Singapore) and changed the stop count at Hungary 2025. The same race and optimiser gave different calls depending only on how fuel burn was removed.

A10. Grid penalties are not applied (the field comes from the qualifying order), and the starting tyres are left free (they are only known at the start). The gradient-boosting opinion is also skipped, because its feature row needs the race in Jolpica.


Part B — Calculations & Physics ⭐⭐

B1. The one-stop formula. Use $s^* \approx (d_2 N - d_1 a_0 + o_2 - o_1)/(d_1 + d_2)$ with the 2026 Las Vegas inputs: $d_S = 0.045$, $d_M = 0.036$, $d_H = 0.017$ s/lap, $o_S = -0.136$, $o_M = 0$, $o_H = -0.039$ s/lap, $N = 50$. Compute $s^*$ for (a) SOFT → HARD on a new SOFT, (b) SOFT → MEDIUM on a SOFT already 3 laps old, (c) MEDIUM → HARD on a new MEDIUM.

Solution

(a) (0.017 × 50 − 0 + (−0.039) − (−0.136)) / 0.062 = 0.947 / 0.062 ≈ 15.3. (b) (0.036 × 50 − 0.045 × 3 + 0 + 0.136) / 0.081 = 1.801 / 0.081 ≈ 22.2. (c) (0.017 × 50 − 0 − 0.039 − 0) / (0.036 + 0.017) = 0.811 / 0.053 ≈ 15.3. The optimiser's exact answers are laps 15, 22 and 15. The formula leaves out warm-up and stint caps, and here that costs at most a lap.

B2. Break-even. With a fresh-tyre gain of 1.078 s/lap (the book's median) and a pit loss of 24.43 s (2026 Singapore's pre-race figure), how many laps must a fresh set run to repay a stop? What about under a VSC, at Chapter 14's near-field VSC loss of 15.671 s?

Solution

Green: 24.43 / 1.078 ≈ 22.7 laps. VSC: 15.671 / 1.078 ≈ 14.5 laps. A VSC on lap 39 of 62 leaves 23 laps, more than both, which is why Leclerc's and Antonelli's lap-39 stops were cheap options worth taking.

B3. Expected points. In 40.4, Verstappen's flexible policy has 13.289 expected points and the one-stop 13.025. Over a 24-race season, what is that difference worth if it held at every race? Why should you not believe that number?

Solution

0.264 × 24 ≈ 6.3 points. It is not believable as a season figure because the gain depends on the circuit's hazard and degradation (at Mexico City 2025 the one-stop was ahead by 0.28 points), and it is within a few Monte Carlo standard errors of zero at 5,000 races per policy.

B4. Brier score. A three-car toy race: the model gives P(win) of 0.5, 0.3 and 0.2, and the second car wins. Compute the Brier score summed over the field. Then compute it for a model that gives 0.2, 0.7 and 0.1.

Solution

(0.5 − 0)² + (0.3 − 1)² + (0.2 − 0)² = 0.25 + 0.49 + 0.04 = 0.78. Second model: 0.04 + 0.09 + 0.01 = 0.14. Las Vegas 2026's real figures were 0.777 for the simulator and 0.149 for the gradient-boosting model.

B5. Hazard. The adapter's Las Vegas hazard multiplier is k = 1.52, and the simulator reports P(≥ 1 incident in 50 laps) = 0.83. If k were 1 (the average circuit), would P(≥ 1) rise or fall, and roughly how would the flexible policy's value change? Argue from Anchor C's sensitivity table.

Solution

It falls, because fewer incidents means fewer chances of a cheap stop. In Anchor C, the flexible policy's gain shrank as k fell (−0.8 s at k = 1.32 to −0.4 s at half that), and P(flex better) fell from 17.2% to 9.1%. Expect the Las Vegas flexible gain of −0.79 s to shrink towards zero, though not to reverse: an option never costs time in the clock-only model when no incident comes.

B6. Pit-lane change. Singapore's green-flag loss was 29.658 s (2024) and 23.207 s (2025). A two-stop pays two stops. By how much does the change in the pit lane alone shift the two-stop's cost relative to a one-stop?

Solution

One extra stop × (29.658 − 23.207) = 6.451 s in the one-stop's favour under the old pit lane. That is why the pool matters. In Anchor C's sensitivity runs, using the 2023–24 loss moved the two-stop's deficit from +9.9 s to +16.6 s.

B7. Pace uncertainty. The Las Vegas pace SD is 0.522 s/lap. Over 50 laps, what is the SD of a car's total race time from this term alone, if each simulated race draws one pace offset per car? Compare it with the 0.258 s/lap qualifying gap between Antonelli and Verstappen.

Solution

One offset per race applies to every lap: 50 × 0.522 = 26.1 s. Antonelli's qualifying advantage is worth 0.258 × 0.972 (the season's slope) × 50 ≈ 12.5 s of race time. The uncertainty is twice the advantage, which is why the engine spreads the win probability so thinly and why it can rate a car starting sixth as favourite.

B8. Monte Carlo error. In the checkpoint run, Verstappen's one-stop P(win) is 0.239 from 1,000 races; in the full run it is 0.198 from 5,000. Compute the binomial standard error of each estimate and say whether the two are consistent.

Solution

SE = √(p(1 − p)/n). At n = 1,000: √(0.239 × 0.761 / 1000) ≈ 0.0135. At n = 5,000: √(0.198 × 0.802 / 5000) ≈ 0.0056. The difference, 0.041, is about 2.8 times the combined SE (√(0.0135² + 0.0056²) ≈ 0.0146). That is on the edge of what noise alone produces. A different number of races also changes every random draw (they are drawn up front, batch by batch), so the two runs are not nested samples. With dozens of probabilities printed per run, one gap of this size is not alarming, and the ranking of the policies is the same in both. If a decision hinged on the second decimal place, you would rerun at 10,000 or more.

B9. The cost of a lap inside the window. Mexico City 2025: Chapter 22's race-stint model put the best lap for Norris's tyres at 36, two laps after his lap-34 stop. With that model's $d_S = 0.054$ and $d_M = 0.053$ s/lap, show that a linear model's cost of stopping $k$ laps early is roughly $k^2 (d_1 + d_2)/2$, and check it for $k = 2$ against Chapter 22's modelled cost of 0.318 s.

Solution

Moving the stop $k$ laps earlier shortens the first stint by $k$ and lengthens the second by $k$. Near the optimum, the first-order terms cancel and the cost is the second-order term ≈ $k^2 (d_1 + d_2)/2$. For $k = 2$: 4 × 0.107 / 2 = 0.214 s. The model's 0.318 s also includes the opening-stint offset and warm-up asymmetries, so the rule of thumb understates it slightly. Setting the cost equal to 1 s gives $k ≈ \sqrt{2 / 0.107} ≈ 4.3$ laps either side of the optimum, about laps 32–40, against the exact window of 33–40. Box Box's pre-race version (best lap 35, $d_S = 0.061$) puts lap 34 at $k = 1$: 0.116 / 2 ≈ 0.06 s, against the model's 0.05 s. Both say the bowl is shallow.


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

C1. Analyze this session: the 2026 Las Vegas GP, Race. Run python -m boxbox validate --year 2026 --gp vegas --driver NOR. Report the robust policy for Norris and his P(win). Then explain why his robust policy can differ from Verstappen's in the same races. Expected output shape: the three-policy table for NOR, a "robust:" line, and the validation block (identical to the chapter's, because the race and winner are the same).

C2. Compare these drivers: 2026 Singapore GP. Using cli.actual_strategies, list the top six finishers' sequences, stop laps and stop statuses. Then, for each of the six, compute the model's best stop lap for its own compounds and starting set (cli.clean_optimum(I, start_compound=..., start_age=...)). Which cars stopped inside the window? Expected shape: a six-row table. Verstappen's best is lap 26 with a window of 20–31; he stopped on lap 32.

C3. Build the strategy: the fuel switch. Reproduce the fuel-correction comparison of 40.6 for the 2026 Barcelona GP only, then add a fourth row in which you scale the pre-race deg by the ratio between the race's own deg and the pre-race deg (hindsight). How many stops does each version recommend? Expected: raw → S-H 15, default → S-H 29, data → S-H-H (20, 43). The hindsight-scaled version should land near the hindsight optimum, M-H-H on laps 17 and 41.

C4. Predict the race: half the uncertainty. Run simulate for the 2025 Mexico City GP with --pace-sd-scale 0.5 --sims 5000. How much does Norris's P(win) rise from 0.455? Does the robust policy change? Expected shape: the same tables, with the pole car's P(win) noticeably higher.

C5. Analyze this session: the phantom stints. For the 2025 Australian GP, list every driver whose stop count differs between strategy.actual_strategies and cli.actual_strategies, with both counts. Expected: 15 of 20 driver-races change, none of them through a zero-length stint: the book's data build already drops those (04_known_weaknesses.py finds none left in any of the 91 Grands Prix). Look at the raw stints of one car with f1data.stints and explain which same-set continuation the adapter merges that the build did not, and which of the two rules you would trust.

C6. Build the strategy: a different robust criterion. simulate picks the robust policy by expected points. Change it to "lowest probability of finishing outside the top three" for the pole car, and rerun the six validation races (03_validation_suite.py --cached reuses the simulations). In which races does the choice change? Explain why a team fighting for a championship might prefer one criterion over the other.

C7. Compare these drivers: GBM vs simulator. For the 14 dry 2026 races of the pole-calibration run, add the gradient-boosting P(win) for the grid-1 car (cli.gbm_probabilities). Plot both against the round, as in Figure 40.10. Which model is closer to the observed 9 of 14?

C8. Predict the race: a race that has not happened. Copy the 2026 Las Vegas qualifying results and pretend the race has not been run: call cli.build_inputs on a RaceContext with race_key=None. Compare the grid (qualifying order, no penalties) with the real one. Which car moves most, and how does the favourite change? Expected: Antonelli starts from P1 in pre-race mode (no grid penalty applied). Check how much his P(win) rises, and what that says about running the simulator before the official grid is published.


Part D — Strategy & Judgment ⭐⭐⭐

D1. Call the pit stop: 2026 Las Vegas, lap 19. The safety car has just been deployed. You are on Verstappen's pit wall: he is P1 on a SOFT that has done 19 race laps (it was 3 laps old at the start), and the model's window for SOFT → MEDIUM is laps 18–27. Nobody has pitted yet. Do you box this lap? Write your call before opening the answer.

What happened

He boxed, as did 15 other cars on the same lap, and took MEDIUMs. The stop was inside the model's window, and the safety car roughly halved its cost. Staying out would have handed the cheap stop to every car behind, and left him to stop at full price later. The robust policy says take the option when the price drops inside the window.

D2. Call the pit stop: 2025 Hungary, lap 31. Norris is on MEDIUMs, 31 laps old. The cars around him (Piastri, Russell, Leclerc) have all stopped once and will stop again. Box Box's clean optimum is a two-stop, and its one-stop window for M-H is laps 32–39. Do you go long and commit to one stop, or follow the two-stop plan? Name the information you would want that Box Box does not have.

What happened

Norris stopped on lap 31, one lap before the model's window, ran HARD to the end, and won by 0.699 s from Piastri's two-stop. The information Box Box lacks: how hard it is to pass at the Hungaroring in practice (Chapter 35's pass model would help), how much life the HARD really had (tyre temperatures), and how Piastri's team would respond.

D3. Design the setup: the model's inputs. You may improve exactly one Box Box input before the next race. Choose between (a) circuit-specific compound offsets, (b) per-car pace uncertainty, and (c) a practice-to-race degradation scaling. Justify the choice with numbers from 40.5–40.7, and say how you would test whether it worked.

D4. The strategist's report. Write the one-paragraph pre-race briefing a strategist would give the team principal for the 2026 Las Vegas GP, using only the Box Box output in 40.3–40.4. It must contain the plan, the window, what would change the plan, and one sentence on what the model cannot see.

D5. When the model and the base rate disagree. Before the 2026 Las Vegas GP, the simulator gave the pole car 20.9% and the pole-to-win base rate for 2023–26 was 62.6%. You are asked for one number to publish. Write a short paragraph explaining what you would publish and why, using the pole-calibration result of 40.6 and Chapter 26's finding that no model beat "pole wins" by a margin that excludes zero.


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

M1 (Chapters 13 + 40). Chapter 13 found the undercut succeeds 42.9% of the time within 3 s. Use that to argue whether a leader should stop at the start of the model's window or at its best lap. Then check the season backtest: what is the median signed timing error of green-flag one-stop winners?

Answer

The median signed error is −1.0 lap: winners stop a little early, consistent with covering the undercut on a flat cost curve.

M2 (Chapters 14 + 27 + 40). Chapter 27's Anchor C ghost simulation gave the flexible one-stop −0.84 s at Singapore. Box Box's ghost run for Las Vegas 2026 gives −0.79 s. Name two input differences between the circuits that could explain why the option is worth about the same at both, and which way each pushes.

M3 (Chapters 20 + 40). Box Box links race pace to qualifying with a slope of 0.971 for 2026. Chapter 20 measured "race gap % = 0.51 + 1.07 × Q1 gap %" across teams. Explain why the two numbers differ and which belongs in a race simulator.

M4 (Chapters 26 + 38 + 40). Ray wants to compare the simulator's P(win) with a bookmaker's price. Using the pole-calibration result (mean simulated P(win) 0.395 for the grid-1 car against an observed 9/14), explain what goes wrong if he feeds the raw simulator probability into Chapter 38's Kelly formula.

M5 (Chapters 22 + 29 + 40). The pre-race model's stop-count agreement was 10/20 in 2025 and 10/14 in 2026; hindsight fixed five 2025 races and no 2026 race. Using Chapter 29's findings about 2026 tyres and stops, propose an explanation and a test.

M6 (Chapters 2 + 18 + 40). Chapter 18's pit-wall loop used pitwall.tyre_changes to define a stop as a change of set. Before the data build dropped zero-length stints and merged same-set continuations, that definition and strategy.actual_strategies disagreed on many driver-races, and Box Box's adapter fixed a different number again; on the rebuilt data the adapter still changes 37 driver-races. Explain why two reasonable stop definitions need not agree on raw timing feeds, and which definition a validation should use.


Part E — Research & Extension ⭐⭐⭐⭐

E1. Per-car pace uncertainty. Replace the field-wide pace SD with one per car: estimate each driver's residual SD in the qualifying → race link over the season so far, shrunk towards the field value. Rerun the pole-calibration study of 40.6. Does the mean P(win) for the grid-1 car approach the observed rate without the arbitrary 0.5 scale? Report the Brier and log scores out of sample (fit on rounds before each race).

E2. Circuit-specific compound offsets. Build an offsets model the way DegModel builds deg: a pooled value per compound, a circuit effect shrunk towards it, fitted only on earlier races. Plug it into cli.build_inputs and rerun the season backtest. How many of the compound misses (for example Las Vegas 2026, Mexico City 2025) does it fix, and does it break any stop-count agreements?

E3. The next Grand Prix. Follow 40.8 for the next race after the snapshot. Before the race, archive the simulate report. After it, run validate and write a one-page post-race review: what the model got right, what it missed and why, in the format of 40.5. Repeat for five races and publish the log.