Realized Spread
Install and import#
npm install fintech-algorithmsimport { 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#
| Name | Type | Notes |
|---|---|---|
bidAtTrade | number | Best bid at execution. |
askAtTrade | number | Best ask at execution. |
tradePrice | number | Executed price. |
side | "buy" | "sell" | Trade direction. |
bidAfter | number | Best bid after the horizon. |
askAfter | number | Best ask after the horizon. |
horizonSeconds | number | Seconds 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#
100100.08100.07"buy"100.11100.19300Call#
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#
Calculation flow#
Realized Spread validation flow
flowchart LR
A["Question: How much of the execution concession remains after the midpoint moves over a declared horizon?"] --> B["Freeze instrument, scope, clock, units, and variant"]
B --> C["Validate Realized Spread inputs"]
C --> D{"Eligible and synchronized?"}
D -- "No" --> E["Reject with topic-specific reason"]
D -- "Yes" --> F["Apply the frozen Realized spread formula"]
F --> G["Expose intermediate value and decision state"]
G --> H{"Direct measure or model-based proxy?"}
H --> I["Report result with its unit and limitation"]
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.
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