TradeReplay — A Backtesting Engine Built for Real Frictions
Strategies are easy to sketch and hard to judge. TradeReplay exists to answer a plain question with realism: given historical data and the frictions we actually pay, brokerage, DP charges, slippage, would this idea have survived contact with the market, and how would the portfolio have behaved while doing so?
TradeReplay: Scaling Backtesting Beyond Nested Loops
When I was working as a financial analyst, one problem struck me again and again: the way we backtested strategies was unnecessarily painful. People often wrote code that worked, but in the most inefficient way imaginable. I once saw a strategy that relied on seven nested loops just to test different conditions. The code would eventually finish running, but it could take hours or even days.
The justification was always the same: “It’s just a one-time run. Why bother optimizing?”
At first, this seemed like a harmless excuse. But in reality, it slowed experimentation to a crawl. Every new variation of an idea meant staring at your computer for hours, waiting for results. And over time, this friction changed behavior — analysts stopped experimenting as freely, because every test carried the hidden cost of wasted time.
Why I Built TradeReplay
That frustration gave birth to TradeReplay.
My goal was clear: make analysts focus on strategy logic and let the system handle efficiency. Analysts shouldn’t need to learn GPU programming or multiprocessing to test their ideas. They should be able to write plain, serial code, and still get performance that makes iteration fast.
TradeReplay parallelizes serial strategies under the hood. It manages data, indicators, portfolios, and trade logs, so analysts only need to decide: under these conditions, do I buy, sell, or hold? Everything else happens in the background.
The Case of the EMA Strategy
To understand why this matters, let me share a concrete example.
When I first tested a simple Exponential Moving Average (EMA) crossover strategy using the old, nested-loop style code, it took nearly six hours to backtest 15 years of historical data. Six hours — just for one strategy run.
I then rewrote it with Python’s multiprocessing library, which cut the runtime down to around 40 minutes. That felt like progress, but it was still far from ideal.
With TradeReplay, the same EMA strategy runs in about 8 minutes even without multiprocessing. And when multiprocessing is turned on inside TradeReplay, the runtime drops further to just two minutes.
That’s the difference between running a single experiment in a day versus running dozens. And that’s exactly the kind of gap that separates slow research from fast discovery.
How TradeReplay Works
The framework is designed to feel familiar, not intimidating. You keep your OHLC data in the Data/ folder, define a strategy class inside Strategies/, and run everything through the engine. The system manages the rest.
A DataLoader helps navigate dates and slice the data. An IndicatorEngine wraps TA-Lib, letting you calculate moving averages, RSI, and other indicators without loops. The Portfolio object updates cash balances, positions, and P&L, while the TradeBook logs trades into a CSV. The Session orchestrates everything: load data, call the strategy, update portfolio, record outcomes.
As the analyst, your job is just to define the logic. The system ensures it runs efficiently.
What This Changes
To me, TradeReplay is not just about writing cleaner code. It’s about restoring the speed of iteration. Inefficient code doesn’t just waste compute cycles — it discourages bold ideas. Analysts run fewer tests, avoid complexity, and settle for less exploration simply because the cost of waiting is too high.
By cutting runtime from six hours to two minutes, TradeReplay flips that equation. Analysts can try more ideas in less time. They can run multiple variations, compare scenarios, and refine strategies faster. Efficiency becomes invisible, and creativity becomes easier.
Looking Ahead
The current version of TradeReplay already solves the pain I faced as an analyst. But the roadmap is bigger. I want to integrate GPU acceleration, multi-core backtests at scale, advanced analytics like drawdowns and risk profiles, and eventually expand it to multi-asset and real-time testing. Visualization layers and enterprise features like collaboration and live-trading integrations are also on the horizon.
Still, the guiding principle won’t change: analysts should write strategies, not infrastructure.
Conclusion
TradeReplay grew out of a frustration with inefficiency. Watching brilliant analysts waste hours on seven nested loops convinced me that the real bottleneck wasn’t the lack of ideas — it was the lack of efficient tools.
What once took six hours now takes two minutes. And that difference is more than just numbers — it’s the difference between cautious research and fearless experimentation.
Backtesting should never be about wrestling with computers. It should be about testing ideas, learning quickly, and discovering what works. With TradeReplay, that finally becomes possible.