Commodities course · Section 5: Commodity Strategies and Backtesting
Backtesting Commodity Strategies: Roll Adjustment, Limit Moves and Costs
How to backtest commodity futures honestly: continuous data, roll adjustment, limit moves, survivorship and selection bias, costs and out-of-sample tests.
Advanced6 min read·5:56 video·Lesson 22 of 26·quiz: 4 questions
▶ Video lesson · 5:56Watch on YouTube ↗
On this page +
- Step 1: get the data right
- Continuous series and rolls
- Measure profit in money
- Data hygiene
- Step 2: realistic execution
- Step 3: limit moves and gaps
- Step 4: watch for biases
- Survivorship and selection bias
- Look-ahead bias
- Overfitting and data snooping
- Step 5: out-of-sample and walk-forward testing
- Step 6: judge with the right metrics
- Step 7: paper trade before you trust it
A commodity backtest replays your trading rules on historical futures data to see how they would have performed, but futures add traps that stock backtests do not have. You need correctly roll-adjusted prices, realistic costs for every trade and every roll, a plan for limit moves and gaps, and tests on data the rules never saw. Done honestly, a backtest tells you whether an idea is worth paper trading; it never guarantees future results.
Step 1: get the data right
Continuous series and rolls
A long backtest needs a continuous series built from many contracts, as explained in the contango and backwardation lesson. Decide and document:
- Roll rule: roll a fixed number of days before first notice or last trading day, or when the next contract's volume or open interest overtakes the current one.
- Adjustment method: back-adjusted (difference) for signals and point-based profit, ratio-adjusted for percentage-based indicators and returns, or a full simulation of each actual contract (the most accurate, and the most work).
Measure profit in money
Example
On a back-adjusted crude series, an old price might show as $5.00 even though crude actually traded far higher at the time. A $1.00 move there looks like +20% on the chart. In reality it was perhaps 3% of the real contract price. Measure results as dollars per contract ($1.00 x 1,000 barrels = $1,000) or use ratio-adjusted data for percentages.
DanioX's commodity pages describe their approach: the jump at each roll is removed by scaling older history, so returns reflect real price moves and today's price is the real quote. You can read the details on the commodity backtest page.
Data hygiene
- Use settlement prices or consistent closing prices, not a mix.
- Check for bad ticks, missing days and contract-month errors.
- Be aware that trading hours changed when exchanges moved from open-outcry pits to electronic trading, which changes how highs, lows and closes compare across years.
- Handle extreme days honestly, such as WTI on 20 April 2020; decide in advance how your test treats them and say so.
Step 2: realistic execution
- No look-ahead on signals. If a signal uses today's close, the earliest realistic fill is the next session's open or later.
- Slippage. Assume at least a tick or two per side in liquid contracts, more in thin markets, at the open, around reports, and on stop orders.
- Commissions and fees per contract per side.
- Roll costs. Each roll is two extra trades. A trend trade held for three months in a monthly contract crosses about three rolls.
Example (illustrative costs): One WTI trade with 1 tick of slippage on entry and exit (2 x $10 = $20) plus $5 of round-turn fees costs $25. If it is held through three monthly rolls, each roll adds roughly another $25 using the same assumptions, so total costs are about $100. If the strategy's average gross profit per trade is $300, costs take about a third of it. Many promising backtests die at this step.
Step 3: limit moves and gaps
- If a market is locked limit, your stop cannot be filled; the test should fill you at the first price at which trading resumes.
- If a market gaps past your stop, the fill is at the open, not at the stop price.
- If your data only has daily bars, you cannot know whether the high or the low came first. Make conservative assumptions, for example that the stop was hit before the target on days when both were touched.
Step 4: watch for biases
Survivorship and selection bias
Survivorship bias means testing only what still exists today. Some contracts have been delisted or became illiquid, and leaving them out flatters results. Selection bias is subtler: choosing the markets to test because they had strong trends recently, or because they are popular now, bakes the result into the test. Define your universe by rules decided in advance, such as minimum liquidity, and keep it fixed.
Look-ahead bias
Using information not available at the time:
- normalising with statistics computed over the whole sample,
- using revised data (for example, later USDA revisions) as if known at the time,
- using COT data on Tuesday when it is only published on Friday,
- using roll dates chosen with hindsight.
Overfitting and data snooping
Testing many parameter values and keeping the best creates a strategy that fits the past, not the future. If a 23-day breakout works brilliantly but 20 and 26 days do not, the 23 is probably luck. Look for plateaus: ranges of parameters that all work reasonably well. Remember the arithmetic from the seasonality lesson: enough tests always produce some false winners.
Step 5: out-of-sample and walk-forward testing
- Split the data: design rules on an earlier period, then test once on a later period you have not touched. If you change the rules after seeing the out-of-sample result, it is no longer out of sample.
- Walk-forward: repeatedly fit on a rolling window and test on the next period, which shows how the process would have worked in real time.
- Cross-market check: a sound commodity rule should work, at least modestly, across most markets and sectors, not just one.
Step 6: judge with the right metrics
Look beyond total profit:
- Number of trades: a few dozen trades say little; aim for hundreds across markets before drawing conclusions.
- Profit factor: gross profit divided by gross loss.
- Maximum drawdown and longest time to recover.
- Share of profitable years and results in the first and second half of the data.
- Results by market, by sector and by side (long and short separately).
- Doubled costs: rerun with costs doubled. If the edge disappears, it is fragile.
DanioX applies checks of this kind, such as a minimum number of trades, profit factor, share of profitable years and a double-cost rerun, before calling a strategy a pass; the methodology page explains its general approach to testing.
Step 7: paper trade before you trust it
A backtest is a hypothesis. Paper trade or trade very small for at least a few months, compare your real fills and costs with the model, and only then decide whether to commit capital. The capstone lesson walks through this process.
Risk
Every backtest is optimistic in ways you cannot fully remove. Expect live results to be worse than the test, and size your positions as if they will be.
Key takeaways
- Use roll-adjusted data for signals and measure profit in money per contract or with ratio-adjusted data, never as a percentage of old back-adjusted prices.
- Trade signals at the next available price, not at the close that created them, and model slippage, commissions and roll costs.
- Limit moves and gaps mean stops do not always fill at the stop price; your test must allow for that.
- Selection bias, look-ahead and overfitting make backtests look better than reality.
- Judge a strategy out of sample, by market, by side and by year, and with doubled costs.
Quiz: check what you learned
0/4 answeredAnswer every question to finish the lesson. Wrong answers are fine: read the explanation and try again.
⚠ Not financial advice — educational signals only. Read the disclaimer.