How the Simulation Works

What a backtest replays, when your rules are judged, how months run in parallel or in order, and what the simulation leaves out.

ConceptBy AlgoLiftUpdated 4 min read
On this page 7What gets replayedWhen a rule is judgedOne trade at a timeMonths, in parallel or in orderWhat it doesn't modelSafety limitsThe same data, the same result

A backtest replays history and runs your strategy on it exactly as you wrote it. AlgoLift's replay is the market itself, print by print: every rule is checked on every trade the exchange recorded, and every order is filled against what was trading at that moment. Knowing what the replay includes, and what it leaves out, is how you judge how far to trust its numbers.

What gets replayed

The record of every resting order that was filled on the exchange, in time order: its price, its size, and the ten best bids and offers as they stood just before it. An aggressive order that sweeps several resting orders leaves several prints. Futures come from CME; stocks from Nasdaq's own feed, so a stock's prints and its order book are Nasdaq's, not every exchange's.

Futures are one continuous series. When the contract rolls, every earlier price is shifted by the roll's price step, so the chart has no jump and the newest contract's prices are the real ones. Stocks are adjusted for splits, not for dividends.

When a rule is judged

Every rule is checked on every print. A value from bars, such as an indicator or a bar's close, reads the last completed bar; the live price reads the print itself. So a rule built only from bars acts on the first trade after a bar closes, and a rule that uses the live price can act inside a bar. A Crossover and a Time Window let you choose: judged at the bar's close, or intrabar.

Before each month, the run loads enough earlier history for your longest lookback, so indicators are ready on its first print. A value still warming up never makes a rule true.

One trade at a time

A strategy holds one trade at a time. No entry fills while a trade is open or an order is on its way, and when several entries fire on the same print, the first in the strategy's order wins. A signal in the opposite direction during a trade is ignored: the engine doesn't reverse a position. A scale-in adds to the open trade, once, on its side.

Before an entry fills, it must pass the run's gates: inside the Daily Time Window, under the day's loss and profit limits and its trade count, past the Entry's cooldown, and in an active regime.

Months, in parallel or in order

A run is cut into calendar months on the New York clock. With Parallel on, the default, the months run at the same time on separate machines, which is much faster. Each month then starts afresh:

  • A trade still open at the month's end is closed there. The results' Summary counts these closes.
  • Counts start over: variables (at zero), cooldowns, daily limits and trade counts, and price-action patterns such as swing points and order blocks.
  • A State Machine publishes nothing in a month until two copies started at different points agree, so one that only counts never publishes.

Indicators, crossovers, VWAP and calendar windows are warmed up from earlier history, so they carry across months unchanged. With Parallel off, one machine runs the months in order and carries everything across, open trades included. Sizing by a percent of equity, a percent daily limit or a drawdown limit turns Parallel off, since each needs the account's state across the whole run.

What it doesn't model

  • Your effect on the market. Your orders never move the price or use up the book.
  • The queue. A resting order's place in line isn't modelled.
  • Limit and stop entries. Entries fill as market orders.
  • The size of a print. With Trade fills, any size fills at the print's price.
  • Depth past ten levels, with Book fills.
  • Margin calls, financing, borrowing and dividends, and exchange fees beyond the commission you set.
  • Rolling a futures position, and its cost: a position held across a roll is priced on the continuous series.

The equity curve and the largest drawdown are measured on closed trades. The daily limits and the drawdown limit watch the open trade too.

Some company figures and economic series can reach a backtest before they were made public, so results that lean on them are optimistic; the Data Source page lists which.

Safety limits

A runaway rule can trade thousands of times a day. If one day passes 300 trades, or 50 regime changes, the engine stops that month and returns the results so far, marked partial. A month that runs out of memory is retried on larger machines.

The same data, the same result

Run the same strategy on the same data and you get the same trades, on any machine. Three things change that: random latency, which draws a new delay for every order; a new futures roll, which shifts every earlier price by its step; and a rebuild of the market data. Each run records the engine version it ran on.