Trading · BraivIQ AI Engineering Playbook
AI In Trading Systems: A Technical Playbook For Machine Learning, Backtesting, Execution And Risk Controls In Automated Markets
Applying machine learning to trading is one of the hardest problems in applied AI - and one of the easiest to fool yourself on. Markets are adversarial, non-stationary and mostly noise; a backtest that looks brilliant is far more often a bug than an edge. This playbook is an honest, engineering-first look at building AI-driven trading systems: the pipeline from data to execution, the backtesting traps that manufacture fake profits, the risk controls that keep a system alive, and the sober reality that most strategies do not work. Educational engineering guidance, not financial advice.
· 13 min read · By BraivIQ Engineering
Adversarial - Markets push back - other participants are actively competing away any edge you find · Non-stationary - The statistical properties of markets drift, so a model that worked can silently stop working · Backtest ≠ edge - A beautiful backtest is more often a bug (lookahead, overfitting) than a real signal · Risk first - Survival depends on risk controls, not on the model - most systems die from risk, not bad prediction
Applying machine learning to trading is one of the hardest problems in applied AI, and one of the easiest to fool yourself on. It attracts enormous interest because the feedback appears to be a clean number - profit - but that clean number hides a swamp of ways to be wrong. Markets are adversarial: unlike image recognition, where the cat does not change its behaviour because you got good at spotting it, markets are made of other intelligent participants who compete away any edge the moment it becomes visible. They are non-stationary: the relationships that held last year drift or reverse. And they are mostly noise: the signal-to-noise ratio is so low that a backtest showing spectacular returns is, far more often than not, a bug rather than a discovery. This playbook is an honest, engineering-first walk through building AI trading systems - and, just as importantly, through the ways they deceive their builders.
Why Trading ML Is Different From Normal ML
It is worth being blunt about why the usual machine-learning playbook underperforms here, because misunderstanding this is the root of most failures. In a normal ML problem the data-generating process is roughly stable and non-adversarial; you can gather more data, the patterns persist, and a good cross-validation score generalises. Markets violate every one of those assumptions. The process is non-stationary, so more historical data can mean training on regimes that no longer exist. It is adversarial and reflexive, so acting on a signal changes the thing you are predicting and invites others to arbitrage it away. And the low signal-to-noise ratio means models overfit ferociously - they memorise noise and present it back to you as a strategy. The consequence is that the discipline of trading ML is less about clever models and far more about not fooling yourself.
The Pipeline: Data, Features, Model, Backtest, Execution, Risk
A systematic trading stack is a pipeline, and every stage is a place to introduce fatal, invisible errors. Market data must be clean, point-in-time correct, and free of the biases discussed below. Features (predictive signals) must be computable using only information available at the moment of the decision - no peeking into the future. The model produces a prediction or a position. The backtest simulates how the strategy would have behaved historically, including costs. Execution turns intended positions into real orders in a live market that pushes back. And risk management sits over everything, sizing positions and enforcing limits. The order matters, but so does the humbling fact that the model - the part everyone obsesses over - is rarely where the money is won or lost. It is won or lost in honest backtesting, realistic execution assumptions, and disciplined risk control.
The Backtesting Traps That Manufacture Fake Profits
If you take one thing from this playbook, take this: most impressive backtests are wrong, and they are wrong in specific, well-known, repeatedly-rediscovered ways. Learning to recognise these traps is more valuable than any model architecture, because they are the mechanism by which intelligent people convince themselves they have found an edge that does not exist.
- Lookahead bias - using information in a backtest that would not have been available at decision time (a future price, a restated figure, a signal computed over the whole dataset). The single most common way backtests lie.
- Survivorship bias - testing only on instruments that still exist today, silently excluding the ones that failed, which flatters returns by removing exactly the losers a real strategy would have held.
- Overfitting and multiple testing - trying many strategies, parameters or features and keeping the best; the winner is very likely fitted to noise. The more things you tried, the less the best one means.
- Ignoring transaction costs and slippage - a strategy that trades often can look highly profitable on paper and lose money once realistic commissions, spread and market impact are subtracted.
- Data-snooping - letting knowledge of the test period leak into design decisions, so the out-of-sample test is not really out-of-sample.
Validation That Respects Time
Because markets are non-stationary and ordered in time, ordinary random cross-validation is actively misleading - shuffling market data destroys the temporal structure and leaks future information into training. Validation has to respect time. Walk-forward analysis - train on a past window, test on the immediately following unseen window, then roll forward - approximates how a strategy would actually have been deployed and re-fitted over time. Keep a genuinely untouched out-of-sample period that you look at once, at the end, and be honest that every time you go back and tweak after seeing it, you have contaminated it. The goal is not a high score; it is an estimate of performance you can actually believe, which is a very different and much harder thing.
Execution: The Market Pushes Back
A backtest assumes you can transact at some historical price. Live markets disagree. Execution introduces slippage (you get a worse price than you modelled), market impact (your own orders move the price against you, more so at size), latency (the market moves between decision and fill), and partial or missed fills. These are not rounding errors - for higher-frequency or larger strategies they routinely turn a paper-profitable system into a real-money loser. Model execution costs conservatively in the backtest, and understand that a strategy's capacity is finite: an edge that works with small size can evaporate as the positions grow and the market impact grows with them. The gap between simulated and realised performance is where many well-engineered systems quietly die.
Risk Management: What Actually Keeps A System Alive
Here is the inversion that experienced practitioners internalise and beginners resist: survival is a risk-management problem far more than a prediction problem. You do not control whether your edge persists, but you do control how much you risk, how concentrated you are, and when you stop. Sensible position sizing (risking only a small, bounded fraction on any single position), diversification across uncorrelated bets, hard drawdown limits, and automated kill switches that halt trading when the system behaves outside expected bounds are what keep a system alive long enough for any genuine edge to express itself. A modest edge with disciplined risk control can endure; a strong-looking edge with reckless sizing gets wiped out by the first regime it did not anticipate. Prioritise not losing catastrophically over trying to win big - because in markets, staying in the game is the whole game.
- Position sizing - risk only a small, predefined fraction of capital per position; never let one trade threaten the whole system.
- Drawdown limits - define in advance the loss level at which you reduce risk or stop, and enforce it automatically, not emotionally.
- Kill switches - automated halts when the system trades outside expected parameters, when data looks wrong, or when losses breach a threshold.
- Diversification - spread risk across genuinely uncorrelated signals and instruments; correlation tends to spike to one exactly when it hurts most.
- Monitoring - continuously watch live performance against backtest expectations; a growing gap is an early warning that the edge is decaying or the assumptions broke.
In most fields, the model is the hard part. In trading, the hard part is not fooling yourself - honest backtesting, realistic execution, and risk control that assumes your edge will fail. The maths that wins is subtraction: costs, biases, and the strategies you had the discipline to reject.
- BraivIQ Engineering
The Sober Conclusion
The honest summary is that most systematic trading strategies do not work, most impressive backtests are artefacts, and any genuine edge tends to be small, hard-won and decaying. That is not a reason to avoid the engineering - the data infrastructure, point-in-time correctness, rigorous validation, realistic execution modelling and automated risk control involved are excellent, transferable systems engineering - but it is a reason to approach it with humility rather than the confidence a good backtest tries to sell you. Build the pipeline properly, treat every beautiful result as guilty until proven innocent, put risk management first, and remember that in an adversarial, non-stationary, noisy environment, the primary skill is not prediction. It is refusing to deceive yourself. Educational engineering guidance only - not financial advice.
References & Further Reading
- Marcos Lopez de Prado - Advances in Financial Machine Learning (backtest overfitting, walk-forward, the pitfalls of ML in finance): https://www.wiley.com/en-us/Advances+in+Financial+Machine+Learning-p-9781119482086
- Bailey, Borwein, Lopez de Prado & Zhu - The Probability of Backtest Overfitting: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2326253
- Campbell Harvey & Yan Liu - Backtesting (multiple testing and the haircut on reported Sharpe ratios): https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2345489
- Ernest Chan - Algorithmic Trading: Winning Strategies and Their Rationale: https://www.wiley.com/en-us/Algorithmic+Trading%3A+Winning+Strategies+and+Their+Rationale-p-9781118460146
- UK FCA - Algorithmic trading compliance and expectations: https://www.fca.org.uk/publications/multi-firm-reviews/algorithmic-trading-compliance-wholesale-markets