Roll Spread Estimator in Python: Inferring the Bid-Ask Spread from Daily Closes

Daily closes are abundant, but bid ask costs are not. Roll’s estimator recovers an effective spread from the serial covariance of price changes, making it useful when only close series are available.

All figures in this post come from a synthetic simulation; the post did not run the estimator on live market data.

Why the spread matters for backtests

Backtests that ignore execution costs can look profitable because they trade at mid prices. Daily closes do not show quoted spreads, but they can reveal an effective spread proxy. That proxy helps you penalize turnover, compare liquidity, and avoid strategies that only work when bid ask costs are absent.

In a backtest, turnover can be high, and a round trip pays roughly one full effective spread, half on each side. If costs are omitted, a strategy may appear to harvest microstructure edges that are actually compensation for liquidity provision. Daily closes are often all you have, so an estimator based on serial dependence is attractive. It is not a substitute for tick data, but it gives a cost-aware signal for screening, position sizing, and turnover-aware optimization.

Roll’s model and its two assumptions

Roll assumes an efficient market where price changes are stationary at least over short intervals such as two months. Under that setup, observed trades bounce around a bid ask spread. The spread estimate is effective, not necessarily quoted, because it comes from transaction price behavior rather than exchange quotes.

The efficient-market assumption says news moves the mid, while the bid ask bounce is a separate, mean-reverting transaction effect. The stationarity assumption says the distribution of price changes does not drift badly over the window used. In practice, a short window can satisfy stationarity but produces noisy covariance. A long window may smooth noise but risks regime change. The estimator therefore trades identification against stability. The original paper is Roll (1984), A Simple Implicit Measure of the Effective Bid-Ask Spread in an Efficient Market; a full text mirror is here.

The estimator formula

The formula is Spread = 2·√(−cov), where cov is the first-order serial covariance of price changes. Roll uses covariance, not autocorrelation or variance, because those statistics can be polluted by news. Trading costs induce negative serial dependence in successive observed price changes, and the bounce reveals the effective spread.

If trades alternate between bid and ask, consecutive price changes often have opposite signs, which produces a negative lag-one covariance. News pollutes variance and autocorrelation, so Roll uses serial covariance instead. Roll’s formula converts the negative covariance into a spread in price units. Because it uses observed transaction prices, the result is an effective spread, not necessarily the quoted spread.

Python implementation on a pandas close series

Pass a clean close series with one adjustment basis and one trading calendar. The function diffs closes, optionally trims a window, computes lag one covariance, and returns None when covariance is not negative. It returns price units, so compare it against prices or dollar costs consistently.

import numpy as np
import pandas as pd

def roll_spread(close: pd.Series, window: int | None = None):
    """Return Roll spread (price units) from a close-price Series, or None if cov >= 0."""
    dp = close.diff().dropna()
    if window is not None:
        dp = dp.iloc[-window:]
    cov = dp.cov(dp.shift(1))  # sample lag-1 covariance of price changes
    if pd.isna(cov) or cov >= 0:
        return None  # not identified: never report zero
    return 2.0 * np.sqrt(-cov)

The function expects a pandas Series indexed by date or row order, with closes already adjusted consistently. Do not mix split-adjusted and unadjusted prices, and do not infer missing trading days from calendar dates without a single trading calendar. A window argument lets you estimate over a short horizon, but the sample covariance will be noisier. The returned value is in the same units as the input price series.

For illustration, the shipped code returns 0.1039 for the synthetic close series [100.0, 100.05, 100.01, 100.06, 100.02, 100.07].

close = pd.Series([100.0, 100.05, 100.01, 100.06, 100.02, 100.07])
roll_spread(close)
# 0.1039

The null-not-zero rule

If the sample covariance is zero or positive, the estimator is not identified. Returning zero would falsely imply no spread, while returning None preserves the distinction between missing information and an estimated cost. A null result is a data quality signal, not a free liquidity result.

The distinction matters in aggregation. If a window is null, treating it as zero spread makes the asset look free to trade. Treating it as missing lets you skip the asset, widen cost bounds, or fall back to another estimator. In a pipeline, log the null share and window length so you can see whether the problem is data hygiene, noise, or market structure.

A synthetic experiment with the shipped code

The results below are synthetic only and show how sample covariance noise and serial dependence affect identification and median estimates. The simulator is the author’s own design, not taken from the literature: AR(1) price changes with innovation sd sigma and coefficient phi, mid = 100 + cumsum, and each observed trade at mid ± spread/2 with equal probability. The experiment used 200 seeds, 252 bars, and a true spread of 0.10.

sigma phi null share median identified estimate
0.50 0 0.46 0.2425
0.20 0 0.17 0.1126
0.05 0 0.00 0.0992
0.20 0.2 0.96 0.0747 (only 4% identified)
0.20 0.4 1.00 no identified estimates

Window sweep at sigma 0.20 and phi 0:

n null share median identified estimate
21 0.33 0.1651
63 0.30 0.1412
252 0.17 0.1126

Noise in the sample covariance is large relative to the bounce term s²/4, and serial dependence in price changes makes most windows null. Among identified runs the median sits above the true spread when sigma is large. This is a selection effect: conditioning on cov < 0 keeps windows where noise pushed covariance more negative. It does not contradict Roll’s Appendix B, which shows the sample estimator is biased downward by Jensen’s inequality and calls that bias immaterial.

When the estimator fails

The null share is the first warning sign. In the synthetic runs above, phi = 0.2 leaves 96% of windows null, and short windows are noisier. Strong trends or momentum can make lag-one covariance nonnegative, and if the true spread is small relative to daily volatility, many windows return None. In those cases the close data cannot support a reliable spread estimate.

Comparison to Amihud and Corwin-Schultz

Amihud illiquidity is a return-to-volume proxy, not a spread. Corwin and Schultz (2012), Journal of Finance 67(2), infer spread from daily high-low ranges. Roll uses only closes and serial covariance, so it is simpler but depends on the bounce mechanism and returned null in the synthetic runs above.

Amihud is useful when volume is reliable, but it measures price impact per dollar traded, not a spread. Corwin and Schultz use daily highs and lows rather than closes. Roll is the closest fit when only daily closes exist, and it should be treated as an effective spread proxy with explicit uncertainty.

FAQ

What does a None result mean?

It means the lag-one covariance was nonnegative or undefined, so the bounce mechanism did not identify a spread. It does not mean the spread is zero. In a pipeline, record the window, adjustment basis, and covariance sign before deciding whether to drop the asset or switch estimators.

Should I clip non-negative covariance to zero?

No. Clipping creates false precision and understates costs. A nonnegative covariance is evidence that the assumed negative serial dependence is absent or overwhelmed by other effects. Return None, then handle missingness explicitly through exclusion, fallback, or conservative cost assumptions.

Is Roll’s spread the quoted spread?

Not necessarily. Roll estimates an effective spread from observed price changes, which reflects execution cost and market structure. It may differ from quoted bid ask spreads, especially when quotes are not available, when trades print away from quotes, or when the effective spread includes other friction.

← Back to all posts