FAQ · Getting systematic research right

How do I backtest a portfolio of several tickers?

Run every ticker in one backtest against one shared account, so positions compete for the same capital and margin. Process bars in time order across all tickers, act on each ticker only when it has a fresh bar, and size each position against total equity. Testing tickers one at a time and adding the results misses the shared capital constraint.

Run every ticker in one backtest against one shared account, so positions compete for the same capital and margin. Process bars in time order across all tickers, act on each ticker only when it has a fresh bar, and size each position against total equity. Testing tickers one at a time and adding the results misses the shared capital constraint.

Why adding single-ticker results is not enough

If you backtest ten stocks separately, each with $10,000, and add the results, you have tested ten accounts. A real portfolio has one account. When five signals fire on the same day, they compete for the same cash, and some cannot be taken. Correlated positions also lose together, so the portfolio's drawdown is usually larger than the average single-ticker drawdown suggests.

What a portfolio backtest needs

  • One clock across all tickers. Bars are processed in time order, so a decision at 10:00 can only use data up to 10:00 for every ticker.
  • Tickers that do not line up. Stocks have holidays, halts and late listings; crypto trades all weekend; activity bars arrive at irregular times. The backtest must cope without inventing bars.
  • Shared buying power. Each new order is checked against equity and open positions across the whole account.
  • Sizing against the portfolio. Each position's size depends on total equity and how many positions are open.
  • Costs per instrument. Spread and commission differ between a large-cap stock and a small one.

Common approaches

  • Ranking and rebalancing. On a schedule, score every ticker, hold the top N, and size them equally or by volatility.
  • Independent signals with a cap. Each ticker has its own entry rule, with a maximum number of open positions and a maximum share of equity per position.
  • Relative value. Positions are taken in pairs or baskets, such as pairs trading.

How Reamer Research handles it

Reamer Research takes a dictionary of tickers in one run, against one account:

import reamer_research as rr

class TopMomentum:
    lookback = 60
    def __init__(self, n=3, qty=10):
        self.n, self.qty = n, qty
    def on_bar(self, d):
        fresh = [t for t in d.tickers if d[t].valid and d[t].close[0] != 0]
        ranked = sorted(fresh, key=lambda t: d[t].close[-1] / d[t].close[0], reverse=True)
        keep = set(ranked[:self.n])
        out = [rr.close_position(ticker=t) for t in fresh if t not in keep and d.position(t) > 0]
        out += [rr.buy_market(self.qty, ticker=t) for t in keep if d.position(t) == 0]
        return rr.orders(*out) if out else None

bars = {t: f'data/{t}.bin' for t in ['AAPL', 'MSFT', 'NVDA', 'AMZN', 'GOOGL', 'META']}
result = rr.backtest(TopMomentum(), bars, spread=0.01, commission_per_unit=0.005)

The same rule runs as a function on_bar(data) or a class as well; the kit's templates/multi_asset.py is a fuller example. Every row of every ticker runs on one wall clock, so rows never need to line up: a ticker with no bar at a given moment carries its last price forward with zero volume, and tv.valid says whether it is fresh. An order that would take open notional past equity times leverage is rejected with a reason, the same rule a margin account applies. ticker_config sets spread, commission and other costs per ticker.

Limits to know

  • The run spans the range all tickers share. Each ticker is cut to the latest first bar and the earliest last bar, so a late listing shortens the run. A changing universe runs period by period, as in the survivorship bias guide.
  • Several tickers need a licence. Evaluation Mode runs one ticker.

A $20 month includes the full kit and the multi-asset templates, so you can run your own universe and cancel if it does not fit.

Next questions

How do I size positions in a backtest?Choose a sizing rule and compute the quantity at each entry. Fixed fractional risks a set share of equity per trade, volatility targeting scales size so each position carries similar risk, and ATR sizing sets quantity so a stop placed a multiple of ATR away loses a fixed amount. Then check the size against your buying power.What is survivorship bias and how do I avoid it?Survivorship bias is testing only on assets that still exist today, which leaves out the companies that were delisted, went bankrupt or were acquired. Avoid it by testing on the universe as it was on each date, with delisted names and their final prices included, from a data source that keeps them.How do I backtest years of minute data that won't fit in RAM?Store the bars in a compact binary file and memory-map it, so the operating system loads only the pages the backtest reads. Converting once from CSV to a fixed-width binary format removes the parse step and the memory limit together. Chunking a CSV by hand also works but breaks indicators and open positions at every chunk edge.How do I backtest a pairs trading strategy with cointegration in Python?Test candidate pairs for cointegration on an in-sample period, estimate the hedge ratio there, then trade the spread out of sample. Go long the spread when its z-score falls below a threshold and short it when it rises above, closing near zero. Estimating the hedge ratio on the whole history is the most common way pairs backtests lie.

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.