Effective Spread
A simple liquidity measure based on spreads.
Definition
The effective spread is the difference between the natural logarithm of the actual transaction price and the natural logarithm of the midpoint prevailing at the time of the trade.
For a given stock $i$ and day $t$, the realized spread on the $k$th trade is defined as:
$$ espread_{i,t,k}=2 \left \ln(P_{i,t,k})  \ln(M_{i,t,k}) \right $$
where $P_{i,t,k}$ is the price of the kth trade and $M_{i,t,k+5}$ is the midpoint of the consolidated BBO prevailing five minutes after the $k$th trade (Hasbrouck (2010)). Aggregating over day $t$, a stock’s effective spread $espread_{i,t}$ is the dollarvolumeweighted average of the effective spread $espread_{i,t,k}$ computed over all trades on day $t$.
Source Code
This example Python code is not optimized for speed and serves only demonstration purpose. It may contain errors.

