Home Live Ticker Fear & Greed
Sign in

Backtesting & Performance

How to Model Realistic Trade Execution in a Backtest

Spot the edge. Swoop in.

A strategy is not fully tested until its signals are translated into plausible orders and fills. A backtest that fills every trade instantly at the exact desired price is measuring a strategy that cannot actually be traded.

Why Does Execution Modeling Matter in a Backtest?

A strategy is not fully tested until its signals are translated into plausible orders and fills. A backtest that fills every trade instantly at the exact desired price is measuring a strategy that cannot actually be traded, because no real order skips the spread, the queue, and the market's reaction to its own size. Execution modeling is the step that turns a list of signals into an honest estimate of what a trader could have actually received.

Every assumption covered below answers the same underlying question in a different form: what would this order have actually cost, and at what price would it actually have filled, given the real mechanics of how orders reach a market. None of these assumptions are visible in the raw price data a backtest usually starts from — they have to be added deliberately, and each one that is skipped quietly shifts the result toward a version of the strategy that could not have been traded.

Commissions and Fees

Even a brokerage advertising zero commissions may still involve a range of other charges: regulatory transaction fees, exchange fees, order-routing fees, per-contract fees for certain instruments, borrow charges on short positions, data or platform costs, and financing costs on any margin used. "Zero commission" describes one line item, not the full cost of trading.

The fee model in a backtest should match the specific brokerage and account structure the strategy is intended for, not a generic assumption carried over from a different account type or a different asset class. A strategy that trades options needs per-contract fees modeled; a strategy that holds short positions needs borrow costs modeled; a strategy using margin needs financing costs modeled. Skipping any of these because the advertised commission is zero produces a backtest that is quietly cheaper to run than the account it is meant to represent.

These charges also do not scale the same way. A regulatory transaction fee is typically a small, fixed rate applied to the dollar value of a sale. A per-contract fee is fixed per unit regardless of the contract's price, which makes it proportionally larger for a lower-priced position than a higher-priced one. A borrow fee accrues daily for as long as a short position is held open, so it grows with holding period in a way a flat commission never does. Applying a single blended cost figure to every trade type in a strategy can understate some trades and overstate others, even when the average happens to look reasonable.

The Bid-Ask Spread

A market buy generally interacts with sell-side liquidity and fills near the ask; a market sell interacts with buy-side liquidity and fills near the bid. Filling every trade at the last traded price or at the bar's close ignores the spread entirely, because the close is a single print that sits somewhere between the bid and the ask, not the price either side of the market was actually offering.

The simple and defensible default model buys at the ask and sells at the bid. A more advanced model estimates the spread directly from quote data, and adjusts it for the stock's liquidity, price level, volatility, and time of day — spreads are typically wider immediately after the open, in lower-priced or less liquid names, and during unusually volatile sessions. For a strategy holding positions for months, the spread cost is close to a rounding error. For a strategy turning the portfolio over weekly in thinner names, it can consume a meaningful share of the apparent edge.

A useful check is to compute the spread as a percentage of the stock's price rather than as a fixed cents figure, since a one-cent spread on a $5 stock is a far larger proportional cost than the same one-cent spread on a $200 stock. Strategies that concentrate in lower-priced or less liquid names should treat the spread as a variable to be measured per stock, not a single constant borrowed from a more liquid part of the market.

Slippage

Slippage is the difference between the price expected when an order is submitted and the price at which it actually fills. Its causes include price movement during transmission, limited liquidity at the desired price, large order size relative to available depth, volatility, gaps between sessions, queue position at a given price level, the order type used, the strategy's own market impact, delayed processing, and stale data feeding the decision.

Several of these causes compound rather than acting independently. A volatile session widens the effective spread at the same time as it increases the odds of a gap, and an order that is large relative to available depth will move the price further precisely when queue position is already unfavorable. Treating slippage as a single flat number per trade is a convenient simplification, but it hides the fact that the worst slippage tends to cluster around the same conditions — thin liquidity, high volatility, and large relative order size arriving together.

Slippage can occasionally be favorable — an order can fill better than expected, just as it can fill worse. A conservative backtest should not depend on favorable slippage to look profitable. Build the model to be pessimistic by default, and treat any favorable slippage that shows up as a bonus rather than as something to rely on. The liquidity and slippage guide covers the underlying mechanics of how order size interacts with available market depth in more detail.

Fill Assumptions

A fill model has to answer a set of questions that raw price data cannot answer by itself. Each question has an optimistic version and a more realistic one.

QuestionOptimistic assumptionMore realistic assumption
Limit order fillsFills instantly the moment the bar's range touches the limit priceRequires confirmed trading volume through that price level before filling
Stop order fillsFills exactly at the stop price regardless of what happened overnightFills at the next available price after a gap, which can be materially worse
Partial fillsEvery order fills completely, in full, every timeLarge orders can receive a partial fill, with the remainder handled explicitly
Volume capsThe strategy can trade any size regardless of the bar's total volumeOrder size is capped as a share of the bar's actual traded volume
Opening ordersFills at a clean theoretical open with no auction mechanicsFills at the actual opening auction price or the first regular-session trade
Order durationUnfilled orders stay live indefinitely until conditions are metUnfilled orders are canceled after a specified duration, as a real order would be
Market-on-closeAssumes the order always meets the close regardless of submission timingChecks whether the order actually met the real submission deadline

The gap between the optimistic and realistic columns is rarely uniform across a strategy's trades — it tends to be largest for exactly the trades that already carry the most risk, such as gap-driven stops and thin-volume fills, which is part of why the optimistic assumption is so easy to mistake for a small simplification rather than a real source of bias.

Market Impact and Capacity

A strategy buying $10,000 of a highly liquid, large-capitalization stock may have negligible price impact. A strategy buying $2,000,000 of a thin small-capitalization stock may move the market against itself simply by trying to execute, and a backtest with no size constraint will happily assume it bought that entire amount at the bar's closing price regardless of how little volume actually traded.

Concrete capacity rules keep this assumption honest:

Participation rate — the order size expressed as a share of the volume trading around it — is a useful common unit across all of these rules, because it lets the same impact assumption be applied consistently to a $50,000 account and a $50,000,000 account trading the same signal. A rule stated only in dollar terms has to be re-derived for every account size; a rule stated in participation-rate terms scales automatically, which makes it easier to test how a strategy's results change as intended capital grows.

The right threshold is not universal — it depends on the strategy's holding horizon and the amount of capital intended to trade it. A slower strategy with a longer holding period can absorb a stricter volume cap without materially changing its behavior; a strategy that depends on fast entries in size has to confront capacity constraints directly rather than assume they will not bind. Re-running the same backtest at several hypothetical account sizes, and watching where returns begin to degrade, is a direct way to locate that strategy's practical capacity limit rather than guessing at it.

Short-Selling Constraints

A short-strategy backtest must additionally assume:

Ignoring short availability can produce trades that could not actually have been placed. A long-short backtest that treats the short leg as a simple mirror image of the long leg — same fill logic, same cost assumptions, no borrow constraint — is not modeling short selling at all; it is modeling a long position with a flipped sign.

The asymmetry between the two sides of a position also matters for risk modeling specifically. A long position's maximum loss is bounded by the amount invested, since a stock price cannot fall below zero. A short position's maximum loss is not bounded in the same way, because there is no ceiling on how high a price can rise before a stop is triggered and filled. A backtest that applies the same stop-based risk arithmetic to both sides without accounting for that asymmetry will understate the tail risk of the short leg specifically.

A Worked Example: The Same Trade, Three Fill Assumptions

Hypothetical example — for education only.

A strategy signals a buy on a stock that closed at $50, sized at 200 shares. The order is submitted the same evening for execution the next session. Three fill assumptions produce three different outcomes.

Fill assumptionFill priceTotal cost (200 shares)Cost above the optimistic fill
Optimistic$50.00 exactly200 × $50.00 = $10,000
Spread-only$50.03 ask200 × $50.03 = $10,006$6
Spread + slippage + capacity penalty$50.11200 × $50.11 = $10,022$22

The optimistic assumption fills exactly at the prior close, as though no spread and no market impact existed. The spread-only assumption fills at a $50.03 ask, adding $6 to the total cost of the position. The third assumption adds slippage and a small capacity penalty on top of the spread, filling at $50.11 and adding $22 to the total cost compared with the optimistic fill — $16 more than the spread-only assumption alone.

Twenty-two dollars on a $10,000 position is a small percentage in isolation. The point is not the size of this one trade; it is that the same gap repeats on every entry and every exit, compounding across the life of the strategy. A strategy whose entire edge is smaller than the gap between the optimistic assumption and the realistic one is not a strategy — it is a modeling artifact that only exists because the backtest assumed fills the market was never actually offering.

Building a Cost-Sensitivity Habit

Always run at least an optimistic, an expected, and a conservative cost scenario, and report all three rather than only the flattering one. The optimistic scenario establishes an upper bound that should never be mistaken for a realistic estimate. The expected scenario reflects the assumptions actually believed to be correct for the intended account. The conservative scenario asks how much room the edge has before it disappears.

A strategy that only survives the optimistic scenario is fragile, not proven. A strategy that survives the conservative scenario, even at a reduced return, has demonstrated something closer to durability. Reporting a single number without the range around it hides exactly the information a reader needs to judge how much confidence the result deserves.

Common Mistakes

Limitations

Even a careful execution model is an estimate, not a guarantee. Real market conditions during actual live trading can be worse — or occasionally better — than any historical simulation, especially during periods of unusual volatility or thin liquidity that the historical sample used to build the model may not have adequately captured. An execution model built from a calm, liquid period will understate costs during a stressed one, and no amount of care in the modeling itself can substitute for testing the strategy against data the model has not seen.

Execution Modeling FAQs

What is slippage in a backtest?

Slippage is the difference between the price expected when an order is submitted and the price at which it actually fills. It comes from price movement during transmission, limited liquidity, large order size, volatility, gaps, queue position, order type, market impact, delayed processing, and stale data. Slippage can occasionally be favorable, but a conservative backtest should not depend on that — the model should be built to be pessimistic by default.

Why do backtests need a spread model?

A market buy generally interacts with sell-side liquidity and fills near the ask, while a market sell interacts with buy-side liquidity and fills near the bid. Filling every trade at the last price or the bar's close ignores the spread entirely and assumes a price that was never actually available to trade at in that direction. A simple default model buys at the ask and sells at the bid; a more advanced model estimates the spread from quote data, liquidity, price level, volatility, and time of day.

How does market impact affect backtest results?

A strategy buying a small dollar amount of a highly liquid stock may have negligible price impact, while a strategy buying a large dollar amount of a thin, small-capitalization stock can move the market against itself as it executes. Capacity constraints — capping order size relative to average daily volume, capping participation in a single bar's volume, or scaling slippage upward as participation rises — keep a backtest from assuming it can trade size the market could not actually have absorbed.

What execution assumptions do short-selling strategies need?

A short-strategy backtest must additionally assume whether the stock was borrowable, what the borrow fee was, whether borrow availability could disappear, whether an uptick-related restriction was active, whether the stock was difficult to borrow, whether the position could be recalled, whether a dividend created a payment obligation, and whether the security could gap beyond the planned stop. Ignoring short availability can produce trades that could not actually have been placed.

Why does a backtest need more than one cost scenario?

Running only an optimistic cost scenario reports the best plausible outcome as if it were the expected one. Running an optimistic, an expected, and a conservative scenario together shows how much of the strategy's apparent edge depends on favorable fills. A strategy that only survives the optimistic scenario is fragile, not proven, and the gap between scenarios is itself useful information about how much room the edge has before ordinary costs consume it.

Related Guides