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 dollar-volume-weighted 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.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  # EffectiveSpread.py import numpy as np name = 'EffectiveSpread' description = """ 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. """ vars_needed = ['Price', 'Volume', 'Mid Point'] def estimate(data): log_midpt = np.log(data['Mid Point'].to_numpy()) price = data['Price'].to_numpy() log_price = np.log(price) espread = 2 * np.abs(log_price - log_midpt) # Daily effective spread is the dollar-volume-weighted average # of the effective spread computed over all trades in the day. volume = data['Volume'].to_numpy() dolloar_volume = np.multiply(volume, price) return np.sum(np.multiply(espread, dolloar_volume) / np.sum(dolloar_volume))