Chapter 40 Key Takeaways — Capstone: Your F1 Race Strategy Simulator
Key Takeaways
- Box Box is 41 modules and one command.
python -m boxbox simulate --year 2026 --gp vegasassembles data → pace + degradation + tyres → strategy → the Monte Carlo engine (neutralisation, start, driver, reliability, overtaking, conditions) → predict → the rules → charts and an HTML report. Of the 14,963 lines of code, 17 modules (5,647 lines) are analysis tools that the race simulation does not need. - Validation is only honest with pre-race inputs. Every input of a past race comes from races that started before it. Only the grid and the starting tyres come from the race, because both are public at the start.
- Integration bugs live between modules. The adapter merges phantom same-set stints (37 driver-races still changed after the data build's own clean-up), prices pit stops on the current pit lane (Singapore: 24.43 s, not 29.15 s), and adds the 2026 pit-loss shift (+1.22 s), all without editing a module.
- On six validation races: stops agreed 4/6, timing 3/6 and compounds 3/6. One AGREE (United States 2026), four PARTIAL and one MISS (Barcelona 2026). Every failed check had a named cause.
- On 34 dry races of 2025–26: the pre-race optimum matched the winner's stop count 21 times, one more than "always one stop" (20). With the race's own degradation it matched 25. Misses were mostly too few stops (10 of 13).
- Inputs beat optimisers. Barcelona 2026's pre-race deg (0.067 / 0.058 / 0.050 s/lap) was about a third of the race's (0.237 / 0.182 / 0.124). No search can recover from that.
- The option beats the commitment. At Las Vegas the flexible one-stop gained 0.79 s on the clock and a planned two-stop lost 14.0 s. Neutralised stops in the backtest were all early, by a median 7.5 laps.
- The engine is under-confident at the front. The mean P(win) of the grid-1 car was 0.395 against 9 wins in 14 (2026). Half the pace SD gives 0.478 and a better Brier score, but treat that as a diagnosis, not a fix.
- The fuel correction changes the call. The same race and optimiser gave stop laps up to 19 laps apart under raw, default and data-driven corrections.
- Running it on the next race takes four steps: move the snapshot dates, fetch, rebuild, simulate. Pre-race mode warns that grid penalties are not applied.
Formulas & Metrics
| Quantity | Formula / definition | Chapter 40 value |
|---|---|---|
| One-stop optimum (linear) | $s^* \approx (d_2 N - d_1 a_0 + o_2 - o_1)/(d_1 + d_2)$ | Las Vegas S→H 15.3; VER S(3)→M 22.2 |
| Cost of stopping $k$ laps off the optimum | $\approx k^2 (d_1 + d_2)/2$ | Mexico City, $k = 1$ (lap 34 vs Box Box's 35): about 0.06 s (model 0.05 s) |
| Break-even laps | pit loss ÷ fresh-tyre gain | 23.39 / 1.078 ≈ 21.7 laps |
| Brier score (win) | $\sum_i (p_i - y_i)^2$ over the field | Las Vegas: 0.777 simulator, 0.149 GBM |
| Stops check | optimum stops = winner's stops | 4/6 races; 21/34 season |
| Timing check | winner's stop inside the 1-s window for its own tyres | 3/6; 6/13 green one-stop winners |
| Compounds check | same compounds, or the winner's sequence within 1 s of the optimum | 3/6 |
| P(≥ 1 incident) | $1 - \exp(-\sum_L k\,\lambda_{phase(L)})$ | Las Vegas, k = 1.52: 0.83 |
Common Mistakes
| Mistake | Fix |
|---|---|
| Validating with book-wide constants (hazard, library, pit-loss tables) that include the race itself | Cut every input at the race's start time, and test that the cut holds |
| Counting OpenF1 zero-length stints as stops | Drop lap_end < lap_start stints and merge same-set continuations |
| Pooling pit stops across a pit-lane change | Use the latest edition with at least 10 used stops |
| Judging the stop lap against the model's favourite compounds | Judge timing on the winner's own compounds and starting set |
| Reading front-row P(win) from the engine at face value | Treat it as a floor; compare with the gradient-boosting model and the pole base rate |
| Quoting a deg number without its fuel correction | Say "default (assumed 100 kg × 0.03 s/kg)", "data-driven" or "raw" every time |
| Trusting a lap simulator's absolute lap time | Use it for sensitivities; take pace from timing data |
| Treating a wet-hazard row as a wet-race simulation | The engine has no wet tyres; the row changes only the incident hazard |
| Running pre-race mode and forgetting grid penalties | Check the official grid; the qualifying order is not the start order |
Decision Checklist (before you act on a Box Box report)
- [ ] Fuel correction behind the deg inputs stated?
- [ ] Pit-loss pool from the current pit lane, with n ≥ 10?
- [ ] Is the model's compound one the teams run at this circuit?
- [ ] Is the 1-s window wide? Then plan the trigger (SC, undercut, traffic), not the lap.
- [ ] Robust policy flexible? Keep the cheap-stop option open; do not commit to the extra stop.
- [ ] Front-row P(win) cross-checked against the gradient-boosting model and the base rate?
- [ ] Race dry? If not, use the wet models of Chapters 15 and 36 alongside.
- [ ] For a race not yet run: grid penalties applied by hand?