How to Account for Trading Costs in Backtesting

A profitable backtest can become unprofitable once you account for the costs of executing its trades. Commissions are an obvious expense, but the prices used to calculate your results can be just as important.

If your backtest assumes entries and exits at prices you would struggle to obtain, its reported performance may overstate the strategy’s advantage. Adding a commission and a fixed slippage allowance doesn’t necessarily solve that problem.

To account for trading costs properly, you need to establish which expenses your backtest already reflects, estimate those it doesn’t, and determine how sensitive your strategy is to changes in those assumptions.

What Trading Costs Should You Include in a Backtest?

The trading costs you need to include depend on the instrument, broker, order types and execution assumptions used by your strategy.

They generally fall into the following categories:

  • Commissions: Charges your broker applies when executing transactions.
  • Exchange and regulatory fees: Additional transaction charges that may apply depending on the market and instrument.
  • Bid-ask spreads: The difference between the prices available to buyers and sellers.
  • Slippage: The difference between an execution price and a specified reference price.
  • Market impact: Changes in available execution prices associated with executing an order, particularly when its size is significant relative to available liquidity.
  • Holding costs: Applicable financing, borrowing or other expenses associated with maintaining a position.

Commissions and exchange fees are explicit costs because they are charged separately. Spreads, slippage and market impact can be reflected directly in the prices at which your orders execute.

These execution-related costs can overlap, so they shouldn’t automatically be added together.

Check how your broker assesses its charges. A futures commission may be quoted per contract, per side, while an equity commission may be assessed per share or transaction. Some expenses depend on transaction value or holding period.

Even commission-free trading can involve substantial execution costs. Before estimating those expenses, establish what the prices in your backtest actually represent.

How Do Spreads and Slippage Affect Backtest Results?

The bid is the highest currently quoted buying price, while the ask is the lowest currently quoted selling price. The difference between them is the bid-ask spread.

Suppose a stock is quoted at a bid of $99.98 and an ask of $100.02. Its spread is $0.04, and its midpoint is $100.00.

If you submit a market buy order and execute at the quoted ask, you pay $0.02 more per share than the midpoint. If you sell at the quoted bid, you receive $0.02 less than the midpoint.

These differences matter when your backtest uses midpoint prices or another price reference that doesn’t adequately represent obtainable execution prices.

A displayed quote also doesn’t guarantee that your entire order can execute at that price. Available liquidity, order size, market movements and execution delays can all affect the final fill.

If your buy order executes at $100.03 instead of the quoted ask of $100.02, the additional adverse execution difference is $0.01 per share. Measured against the midpoint, however, the total difference is $0.03.

Hypothetical buy order: bid $99.98, midpoint $100.00, ask $100.02, fill $100.03. The $0.03 midpoint-to-fill cost comprises a $0.02 half-spread and $0.01 additional adverse execution difference per share.
Hypothetical buy order: the $0.03 midpoint-relative cost per share already includes the $0.02 half-spread and $0.01 additional adverse execution difference.

Slippage can also be favorable. A buy order may execute below its reference price, or a sell order above it.

The benchmark you select determines what your slippage measurement includes.

How to Avoid Double Counting Spreads and Slippage

Consider the previous buy order, which executed at $100.03 against a reference midpoint of $100.00.

The $0.03 midpoint-relative execution difference already incorporates the $0.02 difference between the midpoint and quoted ask, along with the additional $0.01 execution difference.

Deducting both the full midpoint-relative slippage and another $0.02 for crossing the spread would count part of the same expense twice.

The same accounting principle applies when you calculate performance from actual execution prices. Those prices already reflect the spread and other execution differences you experienced.

If your backtest uses simulated fills that account for these expenses, or your trading records use actual fills, deduct only the remaining applicable expenses that aren’t already reflected in the reported results.

Before adding a cost assumption, check whether your backtesting software applies it to the simulated fill price or deducts it separately from profit and loss.

How Do You Calculate Round-Trip Trading Costs?

A round trip includes the transactions required to enter and exit a position. To calculate its total cost relative to a benchmark, measure the execution differences on both sides and add the applicable explicit expenses.

For a buy order, the execution cost per unit is the fill price minus the benchmark price. For a sell order, it is the benchmark price minus the fill price.

Under this convention, unfavorable execution produces a positive cost, while favorable execution produces a negative cost.

Consider a hypothetical long trade involving 100 shares.

At entry, the bid is $99.98, the ask is $100.02 and the midpoint is $100.00. Your order fills at $100.03.

At exit, the bid is $100.28, the ask is $100.32 and the midpoint is $100.30. Your sell order fills at $100.27.

Assume explicit transaction fees of $1 on each side.

Round-trip trading cost breakdown Hypothetical 100-share long trade · USD
Component Calculation Amount
Benchmark-based gross profit ($100.30 − $100.00) × 100 +$30
Quoted spread components ($0.02 + $0.02) × 100 −$4
Additional adverse execution ($0.01 + $0.01) × 100 −$2
Actual fill-based gross profit ($100.27 − $100.03) × 100 +$24
Explicit transaction fees $1 + $1 −$2
Net profit $24 − $2 +$22
Total benchmark-relative cost $30 − $22 $8

The $6 execution difference is already reflected in fill-based gross profit. The $8 total cost is measured against the midpoint benchmark, not an additional deduction from the $22 net result.

If you deducted the $4 spread component again, you would incorrectly report a net profit of $18.

This example assumes consistently timed reference quotes and matching entry and exit quantities. The prices and expenses are hypothetical, not representative estimates for any particular stock.

For futures, multiply the price difference in points by the monetary value of one point per contract and the number of contracts traded. Alternatively, multiply the number of ticks by the tick value per contract and the number of contracts traded. Add any applicable explicit fees not already reflected in the results.

How Do Trading Costs Affect Strategy Expectancy?

Trading costs reduce the average outcome of a strategy when those costs are positive and haven’t already been included in its results.

For a fixed sample of completed trades, you can calculate the relationship as:

Average net outcome = Average gross outcome − Average additional cost

Suppose your strategy produces a hypothetical average gross outcome of $15 per trade, calculated using benchmark prices before execution costs and fees.

If the average additional round-trip cost is $8, the observed net average falls to $7 per trade.

The $8 figure is an assumption for the strategy sample, not an estimate established by the individual trade in the previous section.

You can also express trading expenses relative to initial trade risk. If each trade has a fixed planned initial risk of $100, the $15 gross average represents +0.15R. The $8 cost represents 0.08R, leaving a net average of +0.07R.

When initial risk varies between trades, calculate each trade’s cost in R by dividing its monetary cost by that trade’s consistently defined initial monetary risk. You can then average those individual cost multiples.

Dividing the average dollar cost by the average dollar risk won’t generally produce the same result.

Use a consistent accounting basis when calculating trading expectancy. Compare gross and net outcomes over the same set of completed trades, and avoid deducting expenses that are already reflected in the gross measurement.

A positive gross average tells you relatively little about economic viability until you establish how much of it remains after realistic costs.

Why Are Some Trading Strategies More Sensitive to Trading Costs?

The effect of trading costs depends on their size relative to the strategy’s average gross outcome.

A strategy that earns relatively little per completed trade has less room to absorb execution expenses than one with a larger gross average, assuming comparable costs.

Trading frequency also matters because expenses accumulate as transactions occur. However, a high-frequency strategy isn’t necessarily more vulnerable on a per-trade basis. Its profitability depends on whether its gross outcomes are sufficient to absorb the expenses it incurs.

Other strategy characteristics can influence cost sensitivity:

  • Larger orders relative to available liquidity may execute across several price levels.
  • Strategies with small planned monetary risk can experience a relatively large cost burden when measured in R.
  • Market orders prioritize execution over price certainty. Limit orders, including marketable limit orders, impose a price constraint and may not fill completely or at all.
  • Volatile or less liquid market conditions can make execution prices less predictable.
  • Longer holding periods may introduce financing or borrowing expenses.

These factors can interact. A strategy that trades small price movements during less liquid sessions, for example, may be particularly sensitive to wider spreads and unfavorable execution.

Your objective isn’t necessarily to minimize every individual trading expense. It’s to evaluate how execution affects the strategy’s overall net performance, including the trade opportunities you might lose when attempting to obtain better prices.

How Do You Estimate Realistic Trading Costs for Backtesting?

A useful cost model reflects the conditions under which you intend the strategy to operate. Rather than selecting an arbitrary slippage allowance, build your assumptions from relevant evidence wherever possible.

Start with explicit expenses. Use your broker’s fee schedule and available statements to establish the charges that apply to your intended instrument, position quantity and transaction frequency. Check whether the quoted charges apply per side or per round trip.

Next, establish an execution benchmark. You might use the bid-ask midpoint at order submission, the executable side of the quote, or another reference appropriate to the strategy.

The choice matters because different benchmarks capture different components of execution cost. A benchmark recorded when a trading signal occurs may capture price movement before you submit an order, while a benchmark recorded at submission excludes that earlier movement.

For actual execution records, collect the following information where available:

  • Instrument, order type and quantity.
  • Order submission and execution timestamps.
  • The relevant bid, ask or other reference price.
  • Actual execution price and filled quantity.
  • Explicit transaction fees.
  • Trading session and relevant market conditions.

Compare execution prices against consistently defined benchmarks and convert the differences into monetary amounts. Account for partial fills using the appropriate quantities.

Trading cost model calibration reference
Cost inputEvidence sourceModel application
Commissions and feesBroker fee schedule; statementsApply the relevant per-side, per-fill or quantity-based charges; reconcile against statements.
Bid-ask spreadTimestamped bid and ask quotesEstimate spread by session or condition; include only if absent from modeled fills.
Execution-price differenceOrder timestamps, benchmark quotes and actual fillsMeasure signed differences using matched quantities; separate by order type where useful.
Size and fill behaviorOrder and partial-fill recordsUse quantity-specific assumptions; filled orders alone do not establish fill probability.
Market conditionsSession timestamps and relevant market dataGroup comparable observations; use plausible adverse scenarios when evidence is limited.
Holding expensesFinancing and borrowing recordsApply the relevant rate and holding duration when these expenses apply.

Use observations relevant to the instrument, order type, size and trading conditions. Do not count overlapping execution costs twice.

Examine how these costs vary rather than relying exclusively on one overall average. Your strategy might experience relatively modest execution expenses during one session and substantially different costs during another.

Use observations from instruments, order types and position quantities that reasonably represent the strategy you’re testing. A small collection of fills, particularly from favorable conditions, may not provide a reliable estimate.

The same issues that affect the reliability of a trading strategy’s sample can also affect your cost estimates.

Develop a baseline assumption from representative observations and one or more less favorable scenarios that reflect plausible execution conditions.

If you lack suitable execution records, acknowledge that your assumptions are provisional. Historical quote data and simulated fills can help you evaluate execution assumptions, but simulated fills don’t independently establish the prices you could obtain in live trading.

Update your model as more relevant execution evidence becomes available.

How Do You Include Trading Costs in a Backtest?

There are two principal approaches to incorporating trading costs into strategy testing.

You can deduct additional expenses from an existing trade sample, or you can incorporate cost and execution assumptions into the process that generates the simulated trades.

The distinction matters because more realistic execution assumptions can change more than the profit or loss assigned to each trade.

Adjusting an Existing Trade Sample for Costs

If you already have a historical trade log, you can estimate how additional expenses affect its performance without reconstructing the entire backtest.

First, establish whether the recorded gross outcomes use theoretical prices, simulated fills or actual execution prices.

Then calculate the applicable additional expenses for each completed trade. Where costs vary with quantity, order type or trading conditions, apply the relevant assumptions to individual trades instead of automatically deducting the same amount from every outcome.

Subtract those expenses from the recorded results and recalculate the strategy’s performance metrics using the adjusted trade outcomes.

This approach can help you examine net expectancy, profit factor and the equity curve under alternative cost assumptions.

However, it holds the existing trades, quantities and underlying outcomes fixed. It cannot establish whether an order would have filled at a different price, whether a trade would have been missed or whether different execution would have changed subsequent trading decisions.

Those limitations become especially important when position sizing depends on account equity or previous trade outcomes.

A post-test adjustment is a useful initial evaluation, not a substitute for realistic execution modeling.

Modeling Execution Prices and Order Fills

Execution modeling incorporates assumptions about order handling directly into the backtest.

Begin by checking the available commission, slippage and order-fill settings in your testing platform. Establish whether spread and slippage affect the simulated execution price or appear as separate expenses.

For example, if a futures backtest already uses simulated ask-side prices for buys and bid-side prices for sells, adding the entire quoted spread as another separate round-trip expense may duplicate costs. An additional slippage allowance should represent execution differences not already captured by those prices.

Also consider how the simulation handles different order types.

A market order can execute at a different price from the one observed when the decision was made. A stop-market order can execute beyond its trigger price. A limit order constrains the acceptable execution price but doesn’t guarantee that the order will fill.

Historical open, high, low and close data cannot always establish the sequence of prices within a bar or the liquidity available when a particular price was reached.

A backtest that assumes every touched limit order fills may therefore generate trades that would have been difficult or impossible to execute as modeled.

Use fill assumptions appropriate to the available data and the strategy’s order behavior. More detailed data can help resolve some execution uncertainty, although it cannot eliminate every limitation.

When you change execution assumptions, rerun the simulation where those changes could affect completed trades, fill quantities, position sizing or subsequent trading decisions.

How Do You Stress Test a Strategy Against Higher Trading Costs?

A cost sensitivity test helps you determine how the strategy’s observed performance changes under alternative expense assumptions.

Return to the hypothetical strategy with an average benchmark-based gross outcome of $15 per trade and a fixed planned initial risk of $100.

Using the same completed-trade sample:

  • At $0 additional cost, the average outcome is $15, or +0.15R.
  • At $8 additional cost, it falls to $7, or +0.07R.
  • At $12 additional cost, it falls to $3, or +0.03R.
  • At $15 additional cost, the average outcome reaches break-even.
  • At $20 additional cost, the average outcome becomes a loss of $5, or −0.05R.

Under these fixed-sample assumptions, the break-even average additional cost is $15 per trade. With an illustrative baseline expense of $8, the strategy has $7 of remaining average cost tolerance before its observed net average reaches zero.

This provides a useful measure of sensitivity, but it isn’t a prediction of the strategy’s future break-even cost.

Trading Cost Sensitivity Calculator

Enter additional costs not already reflected in gross results. Default values are hypothetical.

Average net outcome —
Net average in R —
Break-even additional cost —
Remaining cost tolerance —
Positive gross average consumed —
Net average under alternative costs

Calculator has not initialized.

Assumptions: USD; fixed completed-trade sample, quantities and gross outcomes; constant planned initial risk. Additional costs are nonnegative and exclude expenses already reflected in gross results. Net rebates are outside the scope. With variable risk, calculate trade-level R multiples. This is not a forecast or order-fill simulation.

Consider whether expenses are likely to remain relatively stable or increase under particular trading conditions. You could examine wider spreads during less liquid sessions, greater adverse execution during volatile periods or higher costs associated with larger orders.

Applying the same additional expense to every trade may illustrate the arithmetic relationship between costs and expectancy. It won’t necessarily reveal how condition-dependent costs affect drawdowns, losing trades or the sequence of results.

If the scenario changes which orders fill or how the strategy behaves, rerun the backtest using the revised execution assumptions rather than relying on fixed-sample deductions alone.

A strategy that remains profitable under several defensible cost scenarios provides more favorable evidence about cost sensitivity than one that becomes unprofitable after a small adjustment. Neither result establishes future profitability.

What If Your Trading Strategy Is Unprofitable After Costs?

If realistic trading expenses eliminate your strategy’s positive gross average, first determine whether the problem lies in the cost model, execution assumptions or the strategy’s underlying economics.

Check that expenses have been applied correctly. Confirm that you haven’t double counted spread and slippage, deducted fees already reflected in the results or misinterpreted contract multipliers.

Then evaluate whether the cost assumptions reasonably represent the instruments, order quantities and market conditions the strategy is intended to trade.

If particular execution conditions appear responsible for excessive costs, investigate them. Changes to order types, position quantities or trading sessions may reduce certain expenses, but they can also change fill probabilities, trade selection and gross performance.

Reducing trading frequency may help if it removes trades whose expected gross outcomes don’t justify their execution costs. Simply trading less without improving the economics of the remaining trades doesn’t necessarily solve the problem.

Any material changes should be evaluated through further testing, including appropriately separated data, rather than judged solely by improvements to the original backtest.

If the results remain unfavorable under defensible assumptions, the strategy may not have sufficient gross economic advantage to absorb its trading expenses. There is no requirement to find an execution adjustment that makes every strategy viable.

As you continue forward testing your trading strategy, compare its observed execution behavior with the assumptions used in your backtest. Where actual fills are available, use them to reassess your estimates and help distinguish strategy weaknesses from execution problems.

The objective is not to find the cost assumptions that produce the most attractive equity curve. It is to establish assumptions you can defend and determine what the resulting net performance actually tells you.



Author: Shane Daly
Shane started on his trading career in 2005 and sought a more structured approach to his trading methodology. This lead becoming a Netpick's customer in 2008. His expertise lies in technical analysis, incorporating a macro overview for effective trade filtering. Shane's trading philosophy has been influenced by several prominent traders, contributing to his composed and methodical approach to market engagement. Initially focusing on day trading in the Forex market, Shane has since transitioned to a swing and position trading strategy across various markets, including stocks and futures. This shift has allowed him to optimize his time management without compromising his trading performance. By adopting longer-term trading horizons, Shane has successfully reduced his screen time while maintaining consistent returns.