Use split- and dividend-adjusted prices for stock backtests, so a 2-for-1 split does not look like a 50% crash and returns include the dividends a holder received. Keep the unadjusted prices beside them for any rule that depends on the actual price level, such as a minimum share price or a per-share commission.
What adjustment does
- Split adjustment. After a 2-for-1 split, the share price halves while the holder's value does not change. Every price before the split is divided by 2 (and volume multiplied by 2), so the series is continuous.
- Dividend adjustment. On the ex-dividend date the price drops by about the dividend, which the holder receives in cash. Every price before it is multiplied by
1 − dividend / previous close, so the series' return includes the dividend. This is often called a total-return series.
Split-only adjustment keeps prices closer to where they traded but leaves dividend drops in the returns; full adjustment gives correct returns but prices far back in time that never traded.
What goes wrong with each
| Data | Breaks |
|---|---|
| Unadjusted | Splits look like crashes or spikes: stops trigger, signals fire, returns are wrong. Dividends are missing from returns. |
| Split-adjusted only | Each ex-dividend drop looks like a loss; a high-yield stock's return is understated. |
| Fully adjusted | Early prices are lower than they traded, so price-level filters, per-share commissions and round-number levels are off. |
A practical split
- Signals and returns: fully adjusted closes.
- Price filters and per-share costs: unadjusted prices, or the adjusted price times the cumulative adjustment factor.
- Futures: a different problem, rolls between contracts. See futures rolls and FX swap.
How Reamer Research handles it
Reamer Research fills orders on the bars you give it, so the bars should be adjusted before the run. The kit's Alpaca fetcher asks for fully adjusted stock bars by default (adjustment='all', or 'split' or 'dividend'). Databento's equity bars are unadjusted, and its fetcher says so. For your own data, adjustment is a few lines of pandas:
import pandas as pd
import reamer_research as rr
def adjust(bars, splits, dividends):
"""bars: DataFrame indexed by date; splits: {date: ratio}; dividends: {date: cash}."""
factor = pd.Series(1.0, index=bars.index)
for day, ratio in splits.items(): # 2.0 for a 2-for-1 split
factor[bars.index < day] /= ratio
for day, cash in dividends.items():
prev_close = bars['close'][bars.index < day].iloc[-1]
factor[bars.index < day] *= 1 - cash / prev_close
out = bars.copy()
for col in ('open', 'high', 'low', 'close'):
out[col] = bars[col] * factor
out['volume'] = bars['volume'] / factor.where(factor > 0, 1)
return out
raw = pd.read_csv('AAPL_raw.csv', index_col='date', parse_dates=True)
adj = adjust(raw, splits={pd.Timestamp('2020-08-31'): 4.0},
dividends={pd.Timestamp('2020-08-07'): 0.82})
result = rr.backtest(my_strategy, {'AAPL': adj.reset_index()})
rr.backtest takes a pandas DataFrame directly. The volume line above scales volume by the whole factor, dividends included; scale it by the split ratios alone if you use volume in the rule. Keeping the unadjusted frame lets a strategy compare the two, for example as exogenous data attached to the ticker.
Limits to know
- Corporate actions are yours to supply. The engine does not hold a split or dividend calendar; your vendor's adjusted bars, or a list like the one above, provide it.
- Evaluation Mode runs 30 days or 50,000 bars of one ticker. Enough to check the adjustment around one event; longer histories need a licence.
A $20 month includes the full kit, so you can backtest on your own adjusted data and cancel if it does not fit.