All posts

Backtesting6 min read

How to Model Bid–Ask Spread Costs in a Backtest

Build a reproducible bid–ask spread estimate for backtests using timestamped quotes, side-specific fill assumptions, position size, and a clear worksheet.

By TerraTrade Team

Illustration of bid and ask prices on either side of a midpoint beside a backtest worksheet.

What this estimate measures#

A backtest can show a profitable price move while overstating what a trader could have captured if it assumes every buy and sell executes at the chart’s last price. When historical bid and ask quotes are available, you can estimate one important part of that difference: the cost of crossing the quoted spread.

This guide builds a row-by-row worksheet for simulated entries and exits. Its baseline assumption is simple: a marketable buy executes at the ask, and a marketable sell executes at the bid. The estimate is the distance between that assumed execution price and the quote midpoint, multiplied by position size and any applicable contract or unit multiplier. Treat it as a stated backtest convention, not proof of the price a live order would have received.

The bid is the highest price a buyer is willing to pay, the ask is the lowest price a seller is willing to accept, and the quoted spread is ask minus bid. Bid Price/Ask Price | Investor.gov The spread is only one component of execution cost; the worksheet does not include commissions, market impact, or every other factor that may affect a real fill. Investor Tips: Trade Execution

Use the midpoint as the reference#

The midpoint is the arithmetic average of the bid and ask at the quote timestamp:

midpoint = (bid + ask) / 2

Under the touch-fill assumption, the simulated execution is the ask for a buy and the bid for a sell. The estimated spread cost per unit is the absolute difference between that assumed fill and the midpoint. Expressed in SEC effective-spread terms, the midpoint-relative distance is doubled; when a trade executes at the quoted touch, that effective spread equals the quoted spread. SEC.gov | Report on the Practice of Preferencing For a cost worksheet, using the one-way midpoint distance makes it clear how much of the spread the assumed fill pays on that particular side.

For example, if a hypothetical quote is bid 99.98 and ask 100.02, the midpoint is 100.00 and the spread is 0.04. A buy assumed filled at 100.02 is 0.02 per unit above midpoint. A sell assumed filled at 99.98 is 0.02 per unit below midpoint. Each side therefore contributes 0.02 per unit under this convention—not 0.04 per fill.

A complete round trip has an entry and an exit, so record and sum both fills. If both are 100 units at a 0.02 midpoint distance, the estimated spread component is 2.00 per fill and 4.00 for the two fills, before any multiplier. This example is arithmetic, not a typical spread or a claim about achievable execution.

The rows below are hypothetical illustrations. The quote timestamp should be recorded in a consistent, explicit timezone; the displayed UTC timestamps are example values, not sourced market observations.

Trade / legSideQuote timestampBidAskMidpointAssumed executionSizeSpread cost
Example entryBuy2026-11-24 14:30:00.000 UTC99.98100.02100.00100.02 (ask)100 shares$2.00
Example exitSell2026-11-24 15:00:00.000 UTC100.08100.12100.10100.08 (bid)100 shares$2.00

Use a multiplier of 1 when the quoted price and position size already use matching units, such as a share price multiplied by shares. If a contract represents a different quantity, enter the relevant multiplier so the result is in the intended currency. Keep the price increment, size unit, and multiplier explicit; otherwise, the arithmetic may be right but the reported cost may be in the wrong unit.

  • Quoted spread = ask − bid
  • Midpoint = (bid + ask) / 2
  • Assumed execution price = ask for a buy; bid for a sell
  • Spread cost per unit = ABS(assumed execution price − midpoint)
  • Estimated spread cost = spread cost per unit × position size × multiplier

A reproducible process is more useful than a single cost number. Write down how the quote is selected, what qualifies as a valid quote, and how size and multipliers are handled. Decide and document your fill rule (for example, the touch-price assumption: buys at the ask, sells at the bid); treat it as a modeling choice, not a guarantee that a historical quote would have filled any particular live order.

  1. Define the simulated fill events. Create a separate row for every entry and exit, including partial fills if the backtest represents them as separate executions.
  2. Match each event to a quote using a declared timestamp rule. Record the quote timestamp, timezone, bid, and ask used. Avoid silently substituting a later quote for an earlier order time.
  3. Check that the quote is usable for the instrument and event being modeled. If a quote is missing, invalid, or outside your chosen freshness rule, flag the row rather than quietly treating it as a zero-spread fill.
  4. Assign the order side from the simulated transaction: buying uses the ask; selling uses the bid under the touch-fill assumption.
  5. Calculate midpoint, assumed execution price, per-unit spread cost, and total cost using the worksheet formulas. Save the formulas or code version used.
  6. Sum spread costs across all entry and exit rows. Report the total alongside the backtest results, and label it as an estimate under the stated fill rule.

Interpret the result without overstating it#

The touch-fill rule is a clear baseline for estimating quoted-spread cost, but it does not establish that an order of any given size would have executed entirely at the displayed bid or ask. Execution location and method can affect the price paid and overall transaction cost. Investor Tips: Trade Execution The estimate also excludes commissions and other costs by design; keep those as separate line items rather than implying the spread total covers them.

Do not add the full quoted spread to every fill if your intended measure is midpoint-relative cost under this assumption. A buy at ask is half the spread above midpoint, and a sell at bid is half the spread below midpoint when the quote is symmetric around its midpoint. Summing those one-way distances for entry and exit produces the round-trip estimate. Actual spreads need not be constant from one row to another, so calculate from each recorded quote rather than applying one average spread to every trade.

This worksheet answers a narrow question: what spread component results from these quotes and this fill assumption? It does not establish that a strategy is robust, nor does it model market impact, queue position, or the complete execution process.

This is a useful quoted-spread baseline when historical quote data is available. Its strength is transparency; its boundary is that it estimates only the spread component under one explicit fill convention.

A transparent baseline, not a complete execution model

Strengths

  • ✓Uses the actual recorded bid and ask for each modeled fill.
  • ✓Makes entry and exit costs separately auditable.
  • ✓States the fill rule and calculation in a way another trader can reproduce.

Limitations

  • —Treats a touch-price fill as an assumption, not a guaranteed real execution.
  • —Does not estimate commissions, market impact, or all execution effects.
  • —Depends on quote selection, timestamp alignment, and correct size units.

Frequently asked questions#

How do I model bid ask spread in a backtest?

Under the stated marketable touch-fill assumption, assign buys the ask and sells the bid. Calculate the midpoint, then multiply the absolute assumed-fill-to-midpoint distance by position size and any applicable multiplier. Keep the result labeled as an estimate, not a guaranteed fill.

Do I charge the full quoted spread on every entry and exit?

Not for this midpoint-relative worksheet. A buy at ask or sell at bid is one-sided from the midpoint; calculate that distance per fill. Summing the full quoted spread for each fill would use a different measure and overstate this worksheet’s specified cost.

What should the worksheet record?

Use one row per entry or exit fill and record the quote timestamp, bid, ask, side, assumed execution price, and position size. Add a multiplier when the instrument’s contract value requires one to express the result in the intended currency.

Does the result represent my total trading cost?

No. It estimates quoted-spread cost under a chosen fill rule. Execution method and location can affect transaction cost, and this calculation does not include commissions or every other execution effect. Investor Tips: Trade Execution

Make the estimate auditable#

Before relying on the total, inspect a sample of rows and verify that the quote timestamps, sides, arithmetic, and units agree with your written assumptions. Then preserve the worksheet or calculation logic alongside the backtest so the estimate can be reproduced.

Sources#

Your journal writes posts like this about you.

Connect a broker and TerraTrade turns your own trades into the findings that matter.