Write the rule down precisely, get clean data for the instruments and period, set realistic costs, run it, then read both the report and the individual trades. Choose parameters on one part of the history, check them on another, and paper trade before risking money. Each step catches a different way a backtest can mislead.
1. Write the rule precisely
Every decision must be codeable without judgment: what triggers an entry, what size, where the stop and target go, what ends the trade, and when the rule does nothing. "Buy when the trend is strong" is not a rule; "buy 100 shares when the 20-day close average is above the 100-day average, exit when it falls below" is.
2. Get data that matches the rule
- Bar size. The rule's timeframe or finer. A rule that exits intraday needs intraday bars.
- Period. Long enough for many trades and at least one hostile market. See how much historical data.
- Adjustments. Split- and dividend-adjusted for stocks. See adjusted or unadjusted prices.
- Universe. Include delisted names if the rule picks from a list. See survivorship bias.
3. Set realistic costs
Spread, slippage and commission per trade, as your broker would charge them. A strategy that trades often can turn from profit to loss on costs alone. See broker-like commissions.
4. Run it on the first part of the history
Hold back the most recent 20–30% of the data. Tune on the rest. See in-sample and out-of-sample splits.
5. Read the report, then the trades
The summary says whether it made money; the trades say why. Check a handful of winners and losers on the chart: did each entry happen where the rule says it should, and did the exits fill at sensible prices? See why each trade won or lost.
6. Stress it
Double the costs, shift the parameters a little, run Monte Carlo on the trades. A result that survives only one exact setting is likely overfit.
7. Check it once on the held-back data
Run the chosen settings once on the reserved period. If it fails there, go back to step 1, not to step 6.
8. Paper trade, then trade small
Run the same code on live data without money, then with a small size. Compare fills with the backtest's. See paper trading.
How Reamer Research handles it
In Reamer Research steps 3 to 7 are arguments to one call. This class holds the rule from step 1, and start and end split the history:
import reamer_research as rr
class TrendRule:
lookback = 101
def on_bar(self, d):
if d.close[0] == 0:
return None
fast, slow = d.close[-20:].mean(), d.close[-100:].mean()
if d.position() == 0 and fast > slow:
return rr.buy_market(100)
if d.position() > 0 and fast < slow:
return rr.close_position()
costs = dict(spread=0.01, slippage=0.005, commission_per_unit=0.005)
split = 1672531200 # 2023-01-01 UTC
tune = rr.backtest(TrendRule, 'data/SPY.bin', end=split - 1, **costs)
stress = rr.backtest(TrendRule, 'data/SPY.bin', end=split - 1,
**{k: 2 * v for k, v in costs.items()})
check = rr.backtest(TrendRule, 'data/SPY.bin', start=split, **costs)
for name, r in [('tune', tune), ('2x costs', stress), ('held back', check)]:
print(name, r.trades, round(r.net_pnl, 2), round(r.sharpe_ratio, 2))
start and end are epoch seconds UTC and run only the bars inside them. Step 5 is open_viewer=True: the visual trade diagnostics tool charts each trade on its candles with the values the strategy printed. Step 8 runs the same class live through the relay, as in backtest to live without a rewrite. The rule could equally be a plain on_bar(data) function or an object configured with its averages.
Limits to know
- The rule and data are yours. The engine fills orders and reports; it does not suggest rules.
- Evaluation Mode runs 30 days or 50,000 bars of one ticker, with no live trading. Enough to walk through every step on a short slice; full histories and live trading need a licence.
A $20 month includes the full kit, so you can take your own strategy through every step and cancel if it does not fit.