fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Liquidity and Spreads

6 algorithms in Market Microstructure.

In this family#

  1. Quoted Spread contract

    Ask minus bid — what the book advertises. The upper bound on what a small marketable order costs, and routinely wider than what trades actually pay.

    quotedSpread(bid, ask)
  2. Effective Spread contract

    Twice the signed distance from the midpoint to the trade price — what the trade actually paid. Narrower than the quoted spread when trades execute inside it, wider when they sweep.

    effectiveSpread(bid, ask, tradePrice, side)
  3. Realized Spread contract

    The effective spread measured against the midpoint *after* a horizon, which strips out the permanent price impact and leaves what the liquidity provider actually earned. The horizon choice is a modelling decision, not a detail.

    realizedSpread(bidAtTrade, askAtTrade, tradePrice, side, bidAfter, askAfter, horizonSeconds)
  4. Roll Spread Estimator contract

    Infers the effective spread from the negative serial covariance of price changes alone — no quote data required. When the covariance comes out positive the model is contradicted, and reporting zero rather than an imaginary number is the honest handling.

    rollSpread(prices)
  5. Amihud Illiquidity Ratio contract

    Average absolute return per unit of dollar volume — how much price moves per dollar traded. The most widely used low-frequency illiquidity proxy precisely because it needs only daily data.

    amihudIlliquidity(closes, dollarVolumes, scale)
  6. Corwin-Schultz Spread Estimator contract

    Estimates the spread from daily high-low ranges over two days, exploiting that the range reflects both volatility and spread while volatility scales with time and the spread does not. Frequently returns negative values, which are theoretically impossible.

    corwinSchultzSpread(highDay1, lowDay1, highDay2, lowDay2, clipNegative)

What they share#

Every topic here is a record-transform, so once you have called one the rest follow the same shape. Import paths differ only in the final segment:

ts
import { quotedSpread } from "fintech-algorithms/market-microstructure/liquidity-and-spreads/quoted-spread";
import { effectiveSpread } from "fintech-algorithms/market-microstructure/liquidity-and-spreads/effective-spread";

Read them in the order above — the sequence is pedagogical, not alphabetical.

Where this sits#

Market Microstructure collects 29 algorithms across 5 families. For the concept behind this family rather than the call signatures, see the concept guides.