Diary5 min read
Inside our backtest engine
A single-pass simulator we can read end to end, 46 indicators each tested for look-ahead, realistic fills and costs, and stress tests that check a result before you trust it.
Every number QuantPrompt shows comes from a simulator we wrote and test ourselves. It is a single pass over the price bars in plain NumPy and pandas, short enough to read end to end, so we can tell you exactly what each result assumes.
Orders fill the way they would in a real account
- A signal is decided on a bar's close and filled at the next bar's open. Filling at the close you just used to decide is look-ahead.
- Commission and slippage are paid on both sides of every trade, and slippage is charged on stop-loss and take-profit exits too. A stop that fills at exactly its price is a backtest fantasy.
- When an entry and an exit fire on the same bar, the one that fits the position wins: enter when flat, exit when holding.
- You can size each trade as a share of the cash available; the rest stays in cash.
- A position still open at the end is valued at the last close and shown as open, not quietly closed.
Metrics that respect the market's calendar
Sharpe, Sortino and annual return are annualised with the bar density actually in the data: about 252 bars a year for daily stocks, 365 for crypto, roughly 1,764 for hourly US stocks. Assuming 365 days for everything would overstate an equity strategy's Sharpe by about 20%.
46 indicators, each tested for look-ahead
Every indicator is written in plain NumPy and pandas. An automated test computes each one on a price history, then on the same history cut short, and fails if any past value changes when later bars are added. Bars where an indicator is still warming up can never trigger a trade.
Checked against a reference
Before relying on it, we ran the simulator next to a widely used open-source backtesting library on 60 randomly generated price series and signal sets, and compared fills, fees and equity curves bar by bar. They agree except where we chose to be stricter, such as slippage on stop exits.
Stress tests before you trust a result
- Every result is shown next to simply buying and holding the same asset.
- Plateau analysis reruns the strategy on a 9×9 grid of nearby settings, 81 backtests on the same data, to see whether the edge is a broad plateau or a lone peak.
- It also doubles the costs, tests each half of the period on its own and measures how much of the profit the three best trades made.
- Condition analysis removes each rule in turn and judges it on the last 30% of the history, which the comparison never trained on.
Fast enough to run many times
Price data is fetched once per run and reused across every variant, so a sweep of 81 backtests costs one download. Each run records how long parsing, data, indicators and simulation took, which is how we find and fix slow steps.
Owning the engine means we can tell you exactly what it assumes. A backtest you can't inspect is a number you have to take on faith.
Try this strategy
Buy AAPL when the close crosses above its 50-day SMA, sell when it crosses below. 5% stop loss.