A simple liquidity measure based on spreads.

Definition

For a given stock $i$ and day $t$, the bid-ask spread on the $k$th quote (trade) is defined as:

$$baspread_{i,t,k}= \frac{ \text{ask}_{i,t,k} - \text{bid}_{i,t,k} }{ \frac{1}{2} \left( \text{ask}_{i,t,k} + \text{bid}_{i,t,k} \right) }$$

Aggregating over day $t$, a stock’s bid-ask spread $baspread_{i,t}$ is the average of the bid-ask spread $baspread_{i,t,k}$ computed over all quotes on day $t$.

Source Code

This example Python code is not optimized for speed and serves only demonstration purpose. It may contain errors.

# BidAskSpread.py
import numpy as np