FAQ · Getting systematic research right

How do I backtest a trading strategy step by step?

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.

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.

Next questions

What is backtesting in trading?Backtesting runs a trading rule over historical prices as if it had traded at the time, and reports what it would have earned, lost and risked. A useful backtest lets the rule see only data that existed at each moment, fills its orders at prices that were actually available, and charges the costs a real account would have paid.How do I split data into in-sample and out-of-sample?Split by time, never at random. Use the earlier part of your history, often about 70%, to build and tune the strategy, and keep the later 30% untouched until you have stopped changing it. Test once on the held-out part; if you tune again after seeing it, it is no longer out-of-sample.How do I read a backtest report? Sharpe, Sortino, drawdown and profit factor explainedStart with the trade count and costs, then risk-adjusted return (Sharpe and Sortino), then the worst loss from a peak (maximum drawdown), then how wins compare with losses (profit factor and win rate). No single metric is enough; a strategy is only as good as its weakest honest figure.Can I paper trade before going live?Yes, with either product on its own. Reamer Research's relay sends a strategy's orders through the open-source receiver to your broker's paper or demo account. With Reamer Server, a separate order-management core for firms, point your connector at the paper account instead. The licence allows paper and live trading for both. The Reamer Server kit's in-memory paper broker is a wiring check: it fills every order instantly at a made-up price to confirm your server is connected correctly.

Every answer here restates the documents that ship in the kit, which are authoritative. All questions.

Reamer Research

Your first backtest in a minute

Backtesting and live trading in Python and C++. Free to install in Evaluation Mode, with no key or sign-up.

pip install reamer-research

A licence at $20 a month removes every limit. The same code runs unchanged.

Reamer Server

The order-management core for your firm

Your venues, your risk rules on every order, one strategy per CPU core, on your own Linux servers.

$24,000 / year

Or start with a 30-day trial at $2,000.