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.