Backtesting a Moving Average Strategy: Bias, Costs, and Data Checks
Summary
The document demonstrates how a simple 20-day moving average crossover strategy on natural gas futures can look compelling in a vectorized backtest, then lose credibility as realism is added. It recommends inspecting intermediate data and plots, checking missing dates, spikes, duplicates, and price adjustments, and ensuring futures prices account for contract rolls. It also corrects fractional contract positions by rounding to whole lots.
The central pitfalls are look-ahead bias and omitted trading costs. Signals based on the current closing price must be delayed before they determine positions; the article reports that this materially changes the equity curve. Slippage, commissions, liquidity effects, and position controls should also be reflected. It further recommends comparing simulated performance with live trading to spot implementation errors. The example is explicitly a toy strategy, and a vectorized framework is useful for prototyping but less flexible and accurate than event-driven simulation. The reported initial performance should not be treated as reliable evidence of profitability.
Key ideas
- A vectorized backtest can help prototype a strategy, but it may simplify execution and timing details.
- Inspect data, indicators, signals, positions, and returns to make a backtest understandable.
- Validate missing dates, abnormal values, duplicates, adjustments, and futures contract rolls.
- Lag signals so positions use information available before the trade rather than the same closing price.
- Include transaction costs, slippage, liquidity effects, and realistic position management.
- Compare simulated and live results to identify errors and discrepancies.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.