Howwise RSS
Trading Software8 min read

Adjusted vs Unadjusted Prices in a Backtest: What to Use

Short answer

In an adjusted vs unadjusted prices backtest, compute signals on a consistently adjusted series, then take fills, share counts and fees from raw prices as traded. Credit dividends as cash so P&L is total return.

Key takeaways
  • Adjustment is a backward cumulative multiplier, so old prices change while recent prices equal raw, and the gap at the start of history equals cumulative splits and dividends.
  • Raw close on a split day creates a fake crash (-75% for a 4:1 split) that triggers false signals, so split adjustment is the minimum for any indicator.
  • Ratio-based indicators such as RSI and returns barely move on adjusted data, but ATR, fixed-dollar stops and price thresholds like price > 50 change materially.
  • Use adjusted prices for signals, raw prices for orders, sizing and costs, and store raw prices plus a corporate actions table so history is reproducible.
  • A constant adj_close/close factor between events, never above 1, is the fastest proof that a data pipeline is consistent.

What is the difference between raw, split-adjusted and total-return prices?

Raw close is the last trade price on the day as it printed then. Split-adjusted close divides history before each split so the series is continuous. Split+dividend adjusted close (often called total-return adjusted) also scales history down for every cash dividend.

Adjustment is a backward-applied cumulative multiplier. The newest bar has factor 1.0, so adjusted equals raw today. Each older corporate action multiplies all earlier bars by another number below 1, so the oldest prices differ most.

That is why adjusted prices from 2005 can look nothing like what you would have seen on a screen in 2005, and why the same ticker downloaded next year will differ again.

SeriesHandles splitsHandles dividendsTypical label
Raw / unadjustedNoNoAlpaca adjustment=raw, Polygon adjusted=false
Split-adjustedYesNoYahoo Close with auto_adjust=False, Alpaca adjustment=split, Polygon adjusted=true
Split+dividend adjustedYesYesYahoo Adj Close, Tiingo adjClose, Alpaca adjustment=all

How does adjustment math work, and why do unadjusted splits fake a crash?

For a 4:1 split, every bar before the ex-date has prices divided by 4 and volume multiplied by 4. Dollar volume stays the same, which is the sanity check. If raw close is 400 on day t-1 and 100 on day t, the raw return is -75%, but the adjusted prior close is 100 and the return is 0%.

An unadjusted series feeds that fake -75% into everything: a stop-loss fires, an RSI collapses to near zero, a 50-day SMA lags far above price, and a mean-reversion rule goes long a company that lost nothing.

For dividends the multiplier at an ex-date is factor = 1 - dividend / previous close. A 1.00 dividend with a previous close of 100 gives 0.99, so every bar before the ex-date is scaled by 0.99. The multipliers compound: at a steady 2.5% yield, 0.975 ** 20 is about 0.60, so adjusted prices 20 years back sit near 60% of raw. At 2% it is about 0.67, at 3% about 0.54.

# 4:1 split example
raw_prev, raw_new = 400.0, 100.0
print(raw_new / raw_prev - 1)        # -0.75, fake crash
adj_prev = raw_prev / 4
print(raw_new / adj_prev - 1)        # 0.0, correct

# dividend compounding
print(0.975 ** 20)                   # ~0.603

Why do backtest returns change when I swap close for adjusted close?

Raw close-to-close return omits the dividend, because the price drops by roughly the dividend on the ex-date. Adjusted return removes that drop, so it approximates total return with dividends reinvested at the ex-date close. The equity curve gap between the two therefore equals the cumulative dividend yield, compounded.

A buy-and-hold curve on raw close understates a dividend payer by about its yield per year. A strategy that is in and out of the market is affected only while it holds across ex-dates, so the gap between two runs depends on exposure, not just on the ticker.

Indicators move too. How much depends on whether they use ratios or absolute levels.

Indicator or ruleRaw vs adjusted effectWhy
SMA, EMA, Bollinger mid bandLevel differs, shape similarOlder prices are scaled down, so the average sits lower
RSI, returns, MACD signSmall differenceBuilt from ratios or differences of close, so scaling cancels except across ex-dates
SMA crossoversTiming can shift by a bar or moreNear ex-dates the dividend step changes which side of the average price lands on
ATR, fixed-dollar stopsMaterial differenceAbsolute ranges shrink in the old part of history by the factor
price > 50 filtersMaterial differenceAdjusted history may sit far from the price the market actually showed
Warning: A price filter or minimum-price rule on adjusted data tests a price that never existed. A stock adjusted from 62 down to 38 will fail a price > 50 filter in the backtest even though it passed live.

Which price should I use at each stage of an adjusted vs unadjusted prices backtest?

The rule is simple: decisions use a comparable series, executions use what the market quoted. Signals need continuity, so they use adjusted data, with split adjustment as the minimum and one consistent basis across all of OHLC. Orders need real tradable numbers.

Credit dividends as cash on the pay or ex date instead of letting an adjusted series hide them. That keeps share counts honest and lets you model taxes, withholding or a dividend that is never reinvested.

StageUseReason
Signal and indicatorsAdjusted (split at minimum), all OHLC on the same basisContinuous series, no fake gaps
Order and limit pricesRaw as tradedBroker rejects or misprices an adjusted 38.17 limit when the market shows 62.40
Tick rounding, price filters, min priceRawTick size and penny rules apply to real quotes
Share count and position sizingRawshares = floor(capital / raw_price)
Commissions and slippageRaw notionalFees are charged on real dollars
P&LRaw fills plus dividends as cash (total return)Matches a broker statement
BenchmarkTotal-return series for both sidesComparing price return against total return inflates alpha

How do I check that my data pipeline is consistent?

Start from the factor adj_close / close. Between corporate actions it must be constant, and it must never exceed 1 when adjusting backward. Steps in the factor must land on dividend or split ex-dates. On non-event days the pct_change of both series must match. Any raw one-day move beyond 40% is probably an unadjusted split.

The script below flags each problem and labels the divergence dates.

import numpy as np
import pandas as pd

# df: DatetimeIndex, columns close (raw), adj_close, optional split-adjusted column
# actions: columns [date, kind('split'|'dividend'), value]

def diagnose(df, actions, tol=1e-6):
    f = df['adj_close'] / df['close']
    assert (f <= 1 + tol).all(), 'factor above 1'
    step = f.pct_change().abs() > tol
    step_dates = set(df.index[step])
    action_dates = set(pd.to_datetime(actions['date']))
    unexplained = sorted(step_dates - action_dates)
    missing = sorted(action_dates - step_dates)

    r_raw = df['close'].pct_change()
    r_adj = df['adj_close'].pct_change()
    quiet = ~df.index.isin(list(action_dates))
    mismatch = df.index[quiet & ((r_raw - r_adj).abs() > 1e-4)]

    big = df.index[r_raw.abs() > 0.40]   # suspected unadjusted splits
    first_div = (r_raw - r_adj).abs().gt(1e-4).idxmax()
    return dict(unexplained_steps=unexplained, actions_without_step=missing,
                quiet_day_mismatch=list(mismatch), big_moves=list(big),
                first_divergence=first_div)

def rebuild_adjusted(raw_close, actions):
    m = pd.Series(1.0, index=raw_close.index)
    prev = raw_close.shift(1)
    for d, kind, v in actions[['date', 'kind', 'value']].itertuples(index=False):
        d = pd.Timestamp(d)
        if kind == 'split':            # v = ratio, 4 for 4:1
            m[d] *= 1.0 / v
        else:                          # cash dividend on ex-date
            m[d] *= 1.0 - v / prev[d]
    rev = m[::-1]
    factor = rev.cumprod().shift(1, fill_value=1.0)[::-1]
    return raw_close * factor

# compare: (rebuild_adjusted(df.close, actions) / df.adj_close - 1).abs().max()
Tip: Do not compare rebuilt and vendor series with a tight tolerance on dividends before checking whether the vendor reports split-adjusted dividend amounts. Many vendors do, so use the raw dividend of that date and the raw previous close, as the rebuild above does.

How do I run the same strategy on both series and diff the results?

Run one function on both inputs, shift positions one bar to avoid look-ahead, and compare signal dates, trades and equity. Differences in signal dates show you which ex-dates matter to the strategy.

In this example signals come from the series passed in, and returns from that same series, so the adjusted run approximates total return and the raw run is price return. To isolate signal effects, hold the return series constant and swap only the signal input.

  1. Compute the signal series on raw and adjusted data with the same parameters.
  2. Shift positions by one bar before multiplying by returns.
  3. Diff the position series and list the dates where they disagree.
  4. Map each disagreeing date to the nearest ex-date from the actions table.
  5. Compare equity curves and attribute the final gap to dividends and to signal changes.
def run(px, ret_px, fast=20, slow=50):
    sig = (px.rolling(fast).mean() > px.rolling(slow).mean()).astype(int)
    pos = sig.shift(1).fillna(0)
    ret = ret_px.pct_change().fillna(0) * pos
    return sig, (1 + ret).cumprod()

sig_raw, eq_raw = run(df['close'], df['close'])
sig_adj, eq_adj = run(df['adj_close'], df['adj_close'])

# Isolate the signal effect: adjusted signal vs raw signal, same returns
_, eq_sig_only = run(df['adj_close'], df['close'])

diff_dates = sig_raw.index[sig_raw != sig_adj]
trades_raw = sig_raw.diff().abs().fillna(0).sum()
trades_adj = sig_adj.diff().abs().fillna(0).sum()
gap = (eq_adj / eq_raw - 1).iloc[-1]
print(len(diff_dates), trades_raw, trades_adj, round(gap, 4))

Why are historical signals not reproducible, and what do vendors do differently?

Adjusted history is restated every time a new split or dividend occurs, because the multiplier is applied backward. A file saved in January and one downloaded in June differ for every bar before the new ex-date. A live feed streams raw prices, so signals compared against stored adjusted data mismatch the day after a dividend.

The fix is to store raw OHLCV plus a corporate actions table (date, kind, value) and rebuild the adjusted series at run time with a recorded as-of date. That also makes backtests reproducible and avoids a subtle form of look-ahead, where an indicator on adjusted data uses information that only exists after a later dividend.

Vendor / APIOptionWhat it means
yfinanceauto_adjust=True (default in recent versions)Close is already split+dividend adjusted and there is no Adj Close column
yfinanceauto_adjust=FalseClose is split-adjusted only, Adj Close is split+dividend
Alpacaadjustment=raw, split, dividend, allChoose the basis explicitly per request
Polygon aggregatesadjusted=true or falseSplit adjustment only, so dividends stay in the price
Tiingoclose vs adjClose, plus adjOpen, adjHigh, adjLowDaily rows include splitFactor and divCash for the actions table
Warning: Double adjusting is a common bug: calling yfinance with auto_adjust=True and then multiplying by an adjustment factor, or reading Adj Close from a frame where Close is already adjusted. Check which columns exist before you touch them.

What mistakes and debug order should I follow when results differ?

The typical mistakes are mixing raw highs with an adjusted close, adjusting only Close and not Open, High and Low, adjusting volume the wrong way (it should be multiplied by the split ratio, never scaled by dividend factors), and using adjusted prices for share counts or limit prices.

When two runs disagree, work in a fixed order so you find the cause instead of guessing.

  1. Confirm columns: which are raw, split-adjusted or fully adjusted, and whether the library already adjusted them.
  2. Find the first divergence date of the two return series.
  3. Map it to a split or dividend in the actions table and check the factor step matches the expected 1 - D / prev_close or 1 / ratio.
  4. Check for unexplained factor steps and for raw moves beyond 40%.
  5. Decide the intended price basis per stage using the decision table, then rerun.

Common questions

Should I use adjusted close in a backtest?

Use it for signals and indicators, because it removes fake gaps from splits and dividends. Do not use it for order prices, share counts or fees, which need raw prices as traded.

Is adjusted close the same as total return?

It approximates it. Adjusted close assumes each dividend is reinvested at the ex-date close with no tax or fees, so a true total-return calculation that credits cash and tracks shares can differ slightly.

Do splits and dividends affect volume?

Splits do: volume before a split is multiplied by the ratio so share volume is comparable. Dividend adjustment normally leaves volume unchanged, so check that your vendor does not scale it.

Why does my SMA crossover fire on different days with adjusted data?

Ex-dividend steps scale older prices in the average but not the current price, so a close call near the crossover can resolve on the other side. The effect is small for low yields, but it appears exactly around ex-dates.

How do I compute total return versus price return in pandas?

Price return is close.pct_change() on raw prices, and total return is adj_close.pct_change() or (close + dividend_on_ex_date) / close.shift(1) - 1. Cumulate with (1 + r).cumprod() and compare the two curves.

Related topics:backtestingpandasadjusted closecorporate actions