Backtesting-to-Live Parity: an AI Workflow Case Study
An internal project, documented as teaching material: we adapted a trading engine so the same strategy code runs identically in backtest and live, then used it to build and test a momentum strategy end-to-end.
This is the worked example behind our half-day AI Workflow Bootcamp and the AI Workflow for Finance Projects module: taking our own internal systematic trading platform → — where the same strategy code already runs unchanged in backtest and in live — and using it to teach a spec-driven AI workflow rather than tool-first prompting, proven out with an end-to-end momentum strategy.
The Challenge
Backtest-vs-live drift is one of the most expensive, hardest-to-catch failure modes in systematic trading. A strategy that looks robust in research can behave differently once it hits a live execution path — different fill logic, different data timing, different edge-case handling — and the gap is often only discovered after money is at risk.
AI coding assistants make it faster to write a backtester and a live execution layer as two separate codebases — which is exactly how the drift gets introduced. Used tool-first, an assistant will happily generate two plausible-looking implementations. Used spec-first, the same tooling can be pointed at a single shared engine instead.
The Solution — a spec-driven AI workflow
We followed the same spine we teach in the AI Workflow module: spec first, then data readiness, workflow design, guardrails, evaluation, and deployment — in that order, with the AI assistant used inside each stage rather than as a replacement for it.
1. Spec first
Before any code, we wrote down the actual requirement: one strategy interface, called identically by both the backtest loop and the live loop, with no strategy-side branching on which mode it's running in. Success criteria included a defined tolerance for backtest-vs-live output divergence — effectively zero, aside from data-arrival timing.
2. Data readiness
We audited the data paths that differ between research and production — timestamps, corporate actions, look-ahead risk in historical feeds — and normalised them behind a single data-access layer, so the strategy code never sees the difference between historical and streaming data.
3. Workflow design
The engine was structured so the strategy, sized purely on the data and portfolio state it's given, is parity by construction: backtest and live both drive it through the identical interface, with only the data source and order-routing layer swapped underneath.
4. Guardrails
We added automated checks that fail the build if a strategy accesses anything outside the shared interface — the mechanism that actually prevents drift from creeping back in as the codebase evolves, and a control we teach cohorts to demand of any AI-generated trading code.
5. Evaluation
We ran a momentum strategy through the engine end-to-end — signal construction, position sizing, cost and slippage modelling — and diffed its backtest and live-simulated output. Passing that diff, not just a profitable backtest, was the acceptance bar.
6. Deployment
The engine and the worked momentum example became the reference implementation cohorts study directly: real code, not a slide deck, showing spec-driven AI workflow discipline applied to a problem finance practitioners recognise immediately.
Tools & Technologies
Python, with an AI coding assistant used inside a spec-first workflow rather than as an unconstrained code generator — governed by written specs, a shared strategy interface, and automated parity checks, and applied to a momentum strategy for end-to-end evaluation.
The Results
The engine runs the same strategy code in backtest and live with no drift between them — the momentum strategy's backtest and live-simulated results match within the defined tolerance, so research results are trustworthy without a separate reconciliation exercise.
Documented as teaching material, it now anchors the AI Workflow module: a concrete, practitioner-built demonstration that spec-driven AI workflows — not tool-first prompting — are what make AI-assisted development trustworthy for real trading systems.