Skip to main content

Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices

Implements the efficient estimator of bid-ask spreads from open, high, low, and close prices described in Ardia, Guidotti, & Kroencke (JFE, 2024): https://doi.org/10.1016/j.jfineco.2024.103916

Installation

pip install bidask

Usage

There are three functions in this package. The function edge computes a single bid-ask spread estimate from vectors of open, high, low, and close prices. The functions edge_rolling and edge_expanding are optimized for fast calculations over rolling and expanding windows, respectively.

from bidask import edge, edge_rolling, edge_expanding

Function: edge

The input prices must be sorted in ascending order of the timestamp. The output value is the spread estimate. A value of 0.01 corresponds to a spread of 1%.

edge(open, high, low, close, sign=False)
field description
open Array-like vector of open prices.
high Array-like vector of high prices.
low Array-like vector of low prices.
close Array-like vector of close prices.
sign Whether to return signed estimates.

Function: edge_rolling

Implements a rolling window calculation of edge. The input is a pandas data frame. The output is a pandas series of rolling spread estimates. A value of 0.01 corresponds to a spread of 1%.

edge_rolling(df, window, sign=False, **kwargs)
field description
df Data frame with columns 'open', 'high', 'low', 'close' (case-insensitive).
window Size of the moving window. For more information about this parameter, see here.
sign Whether to return signed estimates.
**kwargs Additional keyword arguments to pass to the pandas rolling function. For more information about the rolling parameters, see here.

Function: edge_expanding

Implements an expanding window calculation of edge. The input is a pandas data frame. The output is a pandas series of expanding spread estimates. A value of 0.01 corresponds to a spread of 1%.

edge_expanding(df, min_periods=1, sign=False)
field description
df Data frame with columns 'open', 'high', 'low', 'close' (case-insensitive).
min_periods Minimum number of observations in window required to have a value; otherwise, result is np.nan.
sign Whether to return signed estimates.

Examples

Load the test data.

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/eguidotti/bidask/main/pseudocode/ohlc.csv")

Compute the spread estimate using all the observations.

from bidask import edge
edge(df.Open, df.High, df.Low, df.Close)

Compute rolling estimates using a window of 21 observations.

from bidask import edge_rolling
edge_rolling(df=df, window=21)

Compute expanding estimates starting with a minimum of 21 observations.

from bidask import edge_expanding
edge_expanding(df=df, min_periods=21)

Notes

The rolling estimates:

rolling_estimates = edge_rolling(df=df, window=window, step=step, sign=sign)

are equivalent to, but much faster than:

expected_estimates = []
for t in range(0, len(df), step):
    t1 = t + 1
    t0 = t1 - window
    expected_estimates.append(edge(
        df.Open.values[t0:t1],
        df.High.values[t0:t1],
        df.Low.values[t0:t1],
        df.Close.values[t0:t1],
        sign=sign
    ) if t0 >= 0 else np.nan)

The expanding estimates:

expanding_estimates = edge_expanding(df=df, min_periods=min_periods, sign=sign)

are equivalent to, but much faster than:

expected_estimates = []
for t in range(0, len(df)):
    t1 = t + 1
    expected_estimates.append(edge(
        df.Open.values[0:t1],
        df.High.values[0:t1],
        df.Low.values[0:t1],
        df.Close.values[0:t1],
        sign=sign
    ) if t1 >= min_periods else np.nan)

Cite as

Ardia, D., Guidotti, E., Kroencke, T.A. (2024). Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices. Journal of Financial Economics, 161, 103916. doi: 10.1016/j.jfineco.2024.103916

A BibTex entry for LaTeX users is:

@article{edge,
  title = {Efficient estimation of bid–ask spreads from open, high, low, and close prices},
  journal = {Journal of Financial Economics},
  volume = {161},
  pages = {103916},
  year = {2024},
  doi = {https://doi.org/10.1016/j.jfineco.2024.103916},
  author = {David Ardia and Emanuele Guidotti and Tim A. Kroencke},
}

Metadata

Release files for bidask 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bidask 2.1.0
File Size Uploaded Provenance
bidask-2.1.0.tar.gz 5.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bidask 2.1.0
File Interpreter ABI Platform
bidask-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / bidask-2.1.0.tar.gz

Download URL bidask-2.1.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
eb4c89a1381f4f1299aa36b1c60d845bc325e4fc2fbde6a0703bf6b48b47f600
BLAKE2b-256 checksum
How to use checksums
b200b415dfe911f8bb02a2221c26bb8d8b3a9389b5293de435ba62a3a418d5a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.13 Darwin/23.5.0

Release files / bidask-2.1.0-py3-none-any.whl

Download URL bidask-2.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cbd4e27a53800f041ebaa343656984552ad00f6c4407359a2230c9fbf81a5c3
BLAKE2b-256 checksum
How to use checksums
8d56adb8b70d385ff1f04cc2b680dd918faec3152137f78d7300ecca6b2a7049
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.13 Darwin/23.5.0

Security for bidask 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page