Realistic backtesting: How to properly account for slippage and fees?


Overly optimistic backtests are a common pain point for many algo traders. When simulations show sky-high profits, but real-world trading barely breaks even, the logical question arises: “What am I doing wrong?”.
Most often, the answer lies in underestimating the actual costs incurred in the market — slippage and fees. These seemingly minor factors can completely negate a strategy’s profitability, especially in crypto arbitrage, where margins are often razor-thin and execution speed is critical.
Understanding slippage
Slippage is the difference between the expected price of an order and the actual price at which it is executed. It occurs when the market moves between the time an order is placed and its actual execution. Imagine you want to buy an asset for $100.00, but due to high volatility or low liquidity, your order is filled at $100.05. This is $0.05 of slippage.
Causes of slippage:
Market volatility: The faster prices change, the higher the likelihood of slippage.
Low liquidity: In markets with low trading volume or a sparse order book, large orders can “eat through” available liquidity at the desired price, forcing them to be filled at a worse price.
Order type: Market Orders almost always guarantee execution but not price. Limit Orders guarantee price but not execution. For arbitrage, market orders are often used to ensure speed, which increases slippage risk.
Latency: The time it takes for your order to travel to the exchange and be processed can be enough for the price to change.
Accounting for slippage in Backtesting:
For accurate backtesting, simply “subtracting” a certain percentage isn’t enough. You need to simulate real market behavior:
Based on tick data: This is the most accurate method. If you have access to tick data (every price change), you can simulate the order book and determine the actual price your order would have been filled at, considering available liquidity at each price level.
Fixed percentage/spread (with caution): As a starting point, you can use a fixed slippage percentage (e.g., 0.05%-0.1% of the trade size) or add a fixed “spread” to the bid/ask price. However, this method is crude and may not reflect the real picture across different market conditions.
Dynamic slippage: Account for volatility and trading volumes. During periods of high volatility and low liquidity, slippage will be higher. You can use historical data on actual slippage for specific assets and exchanges if available.
Order size simulation: If you’re trading large volumes, your order might itself cause slippage. Your backtest should account for how your own order would “eat through” the order book.
Understanding commissions (Fees)
Commissions are the fees you pay to an exchange for executing trading operations. Unlike slippage, commissions are predictable, but their impact on profitability is often underestimated, especially in high-frequency trading or low-margin arbitrage.
Types of commissions:
Maker: When you place a limit order that adds liquidity to the order book. Maker fees are typically lower, sometimes even zero or negative (the maker receives a rebate).
Taker: When you place a market order (or a limit order that is immediately filled) that removes liquidity from the order book. Taker fees are always higher.
Withdrawal/Deposit fees: Important for arbitrage strategies that move capital between exchanges.
Tiered fees: Depend on your trading volume over a certain period (usually 30 days) and/or the amount of native exchange tokens held (e.g., BNB for Binance).
Accounting for commissions in Backtesting:
Accurate Maker/Taker model: It’s crucial to simulate whether your order will be a maker or a taker. For arbitrage, where speed matters, orders are often takers.
Volume-Dependent tiers: Model different fee tiers based on historical or projected trading volume. If your strategy qualifies you for a VIP tier, factor in those reduced fees.
Transfer fees: Don’t forget about blockchain fees for transferring assets between exchanges if your arbitrage strategy requires it. These fees can be significant for certain networks (e.g., Ethereum).
General Recommendations for Realistic Backtesting:
Use High-Quality Data: Ideally, tick data or very low-timeframe data (1 min, 5 min) that includes volumes and order book levels.
Err on the side of caution: It’s better to overestimate slippage and commissions in your backtest than to underestimate them. If the strategy is profitable even under worse assumptions, its chances of success increase.
Walk-Forward optimization: Instead of one large backtest, use this method where you optimize your strategy on one time interval and then test it on the next “unseen” interval. This helps prevent overfitting.
Real-time monitoring: Once the algorithm is live, constantly monitor actual slippage and commissions. If they differ significantly from your models, adjust your strategy immediately.
Conclusion
Accounting for slippage and commissions is not just an “add-on option” in backtesting; it’s a fundamental element for any realistic and potentially profitable trading strategy, especially in the dynamic world of crypto arbitrage. Ignoring these factors is a direct path to losses. Only thorough modeling of real market conditions will allow you to build a robust and effective trading algorithm.
Subscribe to my newsletter
Read articles from 27Sphere directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

27Sphere
27Sphere
Analytical and engineering system. Infrastructure for automation, trading, and financial solutions.