fintech-algorithms

Realized Spread

Install and import

bash
npm install fintech-algorithms
ts
import { realizedSpread } from "fintech-algorithms/market-microstructure/liquidity-and-spreads/realized-spread";

Signature

realizedSpread(bidAtTrade, askAtTrade, tradePrice, side, bidAfter, askAfter, horizonSeconds)

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.

Parameters

NameTypeNotes
bidAtTradenumberBest bid at execution.
askAtTradenumberBest ask at execution.
tradePricenumberExecuted price.
side"buy" | "sell"Trade direction.
bidAfternumberBest bid after the horizon.
askAfternumberBest ask after the horizon.
horizonSecondsnumberSeconds after the trade at which the later midpoint is taken. Five minutes is conventional; shorter horizons attribute more of the move to impact.
min: 0

Returns

{ realized_spread, price_impact, effective_spread, … }

The realized spread with the price impact it decomposes against — the two sum to the effective spread.

Errors

  • When horizonSeconds is negative, or a quote is invalid — throws

Complexity: time O(1), space O(1).

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

bidAtTrade
100
askAtTrade
100.08
tradePrice
100.07
side
"buy"
bidAfter
100.11
askAfter
100.19
horizonSeconds
300

Call

realizedSpread(bidAtTrade, askAtTrade, tradePrice, side, bidAfter, askAfter, horizonSeconds)

Returns

object with 18 fields: model, side, direction, trade_price, midpoint_at_trade, midpoint_after, bid_after, ask_after, …

{
  "model": "realized-spread",
  "side": "buy",
  "direction": 1,
  "trade_price": 100.07,
  "midpoint_at_trade": 100.03999999999999,
  "midpoint_after": 100.15,
  "bid_after": 100.11,
  "ask_after": 100.19,
  "horizon_seconds": 300,
  "effective_spread": 0.060000000000002274,
  "realized_spread": -0.160000000000025,
  "realized_spread_relative": -0.0015993602558978912,
  "realized_spread_bps": -15.993602558978912,
  "price_impact": 0.22000000000002728
}

Showing 14 of 18 fields.

Other exports

This module also exports quotedSpread, effectiveSpread, rollSpread, amihudIlliquidity, corwinSchultzSpread, calculate. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams

Realized Spread — calculation map
Realized Spread — decision boundary
Realized Spread — failure boundary
Realized Spread — scenario matrix
Realized Spread — system map

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References

  • SEC Rule 605 adopting release and current FAQ — U.S. Securities and Exchange Commission
  • NYSE Daily TAQ product description — New York Stock Exchange
  • 2024 Rule 605 Amendments adopting release — U.S. Securities and Exchange Commission
  • Rule 605 staff frequently asked questions — U.S. Securities and Exchange Commission, Division of Trading and Markets staff