FAQ · Getting systematic research right

How do I model my broker's commissions in a backtest?

Copy your broker's actual schedule, per share, per contract or a percentage of value, with its minimum and maximum per order, and charge it on every fill, entries and exits both. For a strategy that trades small orders often, the minimum per order is usually what matters most, and a flat per-share rate without it understates the cost.

Copy your broker's actual schedule, per share, per contract or a percentage of value, with its minimum and maximum per order, and charge it on every fill, entries and exits both. For a strategy that trades small orders often, the minimum per order is usually what matters most, and a flat per-share rate without it understates the cost.

The common shapes

ScheduleCharged asTypical of
Per share, with a minimum and a capmax(min, min(qty × rate, cap × value))US stock brokers on their direct-access plans
Per contract, per sidecontracts × rateFutures and options
Percentage of valueqty × price × rateCrypto exchanges, many non-US stock brokers
Zero commission0, cost moves into the spreadRetail stock and ETF apps

Exchange, clearing and regulatory fees often sit on top. Your broker's pricing page lists all of them; a backtest should charge their sum.

A worked example

At $0.005 a share with a $1 minimum per order, 50 shares cost $1.00, not the $0.25 that the per-share rate alone gives. A strategy that makes 500 round trips of 50 shares a year sends 1,000 orders and pays $1,000 in commissions, against $250 without the minimum. On a $10,000 account that difference alone is 7.5% a year.

Zero commission is not zero cost

Commission-free brokers are paid through order routing, and their fills can sit further from the midpoint. Model them with a wider spread or more slippage. See how realistic slippage and spread need to be.

How Reamer Research handles it

Reamer Research charges commission per unit, on both legs or only on opens or closes (commission_mode), and per ticker through ticker_config, so per-share and per-contract schedules are a setting. Minimums, caps and percentage schedules are applied from the fill log after the run. This function strategy is charged both ways:

import reamer_research as rr

def on_bar(d):
    if d.close[0] == 0:
        return None
    up = d.close[-1] > d.close[-12:].mean()
    if d.position() == 0 and up:
        return rr.buy_market(50)
    if d.position() > 0 and not up:
        return rr.close_position()

def broker_fee(fill, rate=0.005, minimum=1.00, cap=0.01):
    value = fill['qty'] * fill['price']
    return max(minimum, min(fill['qty'] * rate, cap * value))

flat = rr.backtest(on_bar, 'data/SPY_5min.bin', lookback=12,
                   spread=0.01, commission_per_unit=0.005)
fills = flat.json()['trade_log']
charged = sum(f['fees'] for f in fills)
actual = sum(broker_fee(f) for f in fills)
print(f'{len(fills)} fills: per-share only {charged:.2f}, with minimum {actual:.2f}')
print(f'net {flat.net_pnl:.2f} -> {flat.net_pnl + charged - actual:.2f}')

trade_log has one row per fill with its price, quantity and the fees the engine charged, so any schedule, including a percentage (fill['qty'] * fill['price'] * rate) or tiered monthly rates, is a function of it. Per-contract futures fees go straight into ticker_config={'ES': {'commission_per_unit': 2.25}}. The same rule could be a class or a configured object.

Limits to know

  • The engine's built-in commission is per unit. A minimum, a cap or a percentage is computed from trade_log as above, which leaves fills unchanged; only an equity-dependent rule such as sizing from the account balance would see the difference.
  • Evaluation Mode runs 30 days or 50,000 bars of one ticker. Enough to compare schedules on your own strategy.

A $20 month includes the full kit, so you can run your strategy under your broker's real schedule and cancel if it does not fit.

Next questions

How realistic do slippage and spread need to be in a backtest?Realistic enough that the result survives them. Set spread, slippage and commission per instrument from what your broker actually charges, let spread and slippage widen when the market moves fast, and then rerun at one and a half and two times those costs. A strategy whose edge disappears under slightly higher costs was never a reliable edge.How do I include short-selling borrow costs in a backtest?Charge each short trade its borrow fee, the annual rate times the value borrowed times the days held over 360, and check that the stock could be borrowed at all. Easy-to-borrow large caps cost well under 1% a year; hard-to-borrow names can cost many times that, and those are often the stocks a short-selling rule picks.Should my backtest use market or limit orders?Whichever you will use live, because they test different things. A market order always fills and pays the spread and slippage. A limit order saves that cost but fills only when price comes to it, and misses the trades that run away. A backtest of limit entries is honest only if a limit fills when price trades through it, and the trades it missed stay missed.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.

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.