Backtesting execution-cost guide

Model slippage, fees, and market impact without making a backtest look safer than it is

Separate explicit fees from spread and execution effects, define when and how orders fill, scale assumptions to liquidity and order size, then test whether strategy conclusions survive less favorable execution.

BotSpot capabilities

Research by conversation

Ask the agent to investigate markets, companies, filings, strategies, and your connected account context.

Place approved direct trades

When direct trading is enabled, request a one-time trade in plain English, inspect the order, and approve it before submission.

Build complete algorithms

Create, revise, backtest, connect, and operate Lumibot strategies without assembling the full application stack yourself.

Use the AI client you prefer

Work in BotSpot or connect through ChatGPT, Claude, Cursor, Codex, and other compatible MCP clients.

1. Build an execution-cost ledger before running the backtest

List every cost and fill assumption separately before inspecting performance. A single generic transaction-cost number can hide double counting, missing costs, or unrealistic execution.

Keep explicit charges, spread, price movement, and market impact identifiable even if the backtesting engine combines some of them into one fill price.

  • Broker commissions, minimum charges, and volume tiers.
  • Exchange, clearing, regulatory, contract, and asset-specific fees where applicable.
  • Bid-ask spread paid when an order takes available liquidity.
  • Price movement between the strategy decision, order submission, and fill.
  • Liquidity limits, partial fills, queue behavior, and market impact.

2. Model commissions from the intended broker workflow

Use the current official fee schedule for the intended broker, account type, market, asset, order, and volume tier. Do not copy a fee from a different broker or assume commission-free means cost-free.

Represent each fee in the form it is charged: per order, per share, per contract, percentage of value, minimum charge, or tiered rate. LumiBot supports flat, percentage, and per-contract trading-fee inputs for backtests.

  • Record source URL and verification date.
  • Apply buy-side and sell-side charges where required.
  • Include minimums and tier thresholds instead of averaging them away.
  • Recheck volatile fee schedules before publishing or rerunning material analysis.

3. Keep spread and slippage definitions consistent

A marketable buy generally executes against the ask and a marketable sell against the bid. A fill model using bid and ask quotes can therefore include spread directly in simulated fill prices.

Slippage describes a difference between a declared reference price and the simulated or actual fill. State whether the reference is decision price, quote midpoint, arrival price, last trade, bar close, or another observable value.

  • Do not subtract a separate spread charge when the fill model already buys at ask and sells at bid.
  • Do not treat a bar close as both decision price and guaranteed fill unless timing makes that possible.
  • Use quote data when available; document any bar-based spread proxy when it is not.
  • Keep favorable price improvement possible only when the selected model and evidence support it.

4. Make fill timing and order behavior feasible

Define when the strategy observes data, when it submits an order, which market session applies, and which later observation can first produce a fill. Same-bar fills can use information unavailable when the order would have been placed.

Order type changes the simulation. Market orders favor execution certainty but can slip. Limit orders constrain price but may remain unfilled. Stops become eligible only after their trigger conditions occur.

  • Match data resolution to decision and execution timing.
  • Reject fills based on stale prices or closed-market data.
  • Model unfilled, canceled, expired, and rejected orders where relevant.
  • Preserve pending orders across bars instead of silently converting them into fills.

5. Treat liquidity and partial fills as strategy inputs

Historical price bars do not guarantee that the full strategy order could trade at one displayed price. Available quantity, order-book depth, queue position, and competing orders affect both fill quantity and timing.

Set liquidity rules from data and intended trade size rather than one universal volume percentage. Test what happens when only part of an order fills and the remainder stays open, reprices, expires, or is canceled.

  • Compare order size with relevant traded volume and available depth.
  • Prevent a simulated fill from consuming unlimited quantity at one price.
  • Update cash, positions, exits, and risk rules after each partial fill.
  • Check whether delayed completion changes later signals or creates overlapping orders.

6. Scale market impact to size, liquidity, volatility, and time

Market impact is the price response associated with consuming liquidity and revealing demand or supply. Its size depends on factors including order size, trading volume, depth, volatility, and execution duration.

A bar-only backtest cannot observe the order book the hypothetical trade would have consumed. Any impact result remains a model estimate. Declare model form, inputs, calibration period, and unsupported markets.

  • Avoid one fixed market-impact value across symbols and order sizes.
  • Increase scrutiny when orders represent a larger share of available liquidity.
  • Distinguish temporary execution effects from persistent price movement when the model does.
  • Recalibrate external model defaults before relying on them in a different market or period.

7. Run sensitivity tests instead of choosing one convenient cost

Test a documented base case plus less favorable execution cases. Derive ranges from current fee schedules, historical quotes, intended participation, and observed execution rather than publishing universal defaults.

Report gross results, net results, turnover, total modeled costs, and the cost level at which the strategy conclusion changes. A strategy surviving only its most optimistic fill model needs more evidence.

  • Widen spreads using observed distributions for relevant symbols and sessions.
  • Delay fills and reduce eligible fill quantity.
  • Raise explicit costs according to plausible account or volume tiers.
  • Stress high-volatility, low-liquidity, and extended-hours periods separately.
  • Change one assumption at a time, then test combined adverse conditions.

8. Compare models with observed execution carefully

Paper trading can validate order construction, scheduling, state, and broker integration, but its fills remain simulated. Alpaca documents that its paper environment omits market impact, latency slippage, queue position, price improvement, and regulatory fees.

Where controlled live observations exist, compare decision timestamp, reference quote, submit time, acknowledgments, partial fills, final fill, explicit fees, order size, and market conditions. Historical observations can inform calibration but cannot guarantee future execution.

Limitations and risk

No execution model reproduces every venue, queue, counterparty, outage, rejection, or future liquidity condition. More detailed assumptions reduce known simplifications; they do not turn simulated results into expected returns.

Broker fees, market structure, data coverage, and backtesting-engine defaults can change. Preserve configuration, sources, dates, and raw trade records so results can be audited and rerun.

Frequently asked questions

What trading costs should a backtest include?

Include applicable broker, exchange, clearing, regulatory, and contract fees plus bid-ask spread, slippage, fill timing, liquidity limits, partial fills, and market impact. Financing, borrow, conversion, and product costs may also matter for some strategies.

What slippage value should I use?

No universal value fits every strategy. Derive assumptions from intended order type, asset, session, quote data, volatility, liquidity, order size, latency, and observed execution. Test multiple documented cases.

Does commission-free trading remove transaction costs?

No. Spread, price movement, market impact, regulatory or product fees, financing, and missed or partial fills can remain even when the broker charges no stated commission.

Can paper trading estimate live slippage accurately?

Not by itself. Paper systems use simulated fill and liquidity rules and may omit market impact, queue position, latency effects, fees, or price improvement. Use paper trading mainly for operational validation and document its fill assumptions.

How should a backtest handle partial fills?

Fill only eligible quantity under the declared liquidity model, update portfolio state after each fill, and keep the remainder pending, canceled, or expired according to the order rules. Do not assume every order completes immediately.

Sources

Sources verified 2026-08-14.