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

Effective Spread

Install and import#

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

Signature#

effectiveSpread(bid, ask, tradePrice, side)

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.

Parameters#

NameTypeNotes
bidnumberBest bid at the time of the trade.
asknumberBest ask at the time of the trade.
tradePricenumberExecuted price.
side"buy" | "sell"Trade direction, usually from a classifier in D11-F01.

Returns#

{ effective_spread, relative, midpoint, price_improvement }

The effective spread and the price improvement against the quote.

Errors#

  • When side is not buy or sell, or ask is below bid — 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#

bid
100
ask
100.08
tradePrice
100.07
side
"buy"

Call#

effectiveSpread(bid, ask, tradePrice, side)

Returns#

object with 17 fields: model, bid, ask, midpoint, quoted_spread, quoted_spread_relative, quoted_spread_bps, state, …

{
  "model": "effective-spread",
  "bid": 100,
  "ask": 100.08,
  "midpoint": 100.03999999999999,
  "quoted_spread": 0.0799999999999983,
  "quoted_spread_relative": 0.0007996801279488034,
  "quoted_spread_bps": 7.996801279488034,
  "state": "inside-quote",
  "trade_price": 100.07,
  "side": "buy",
  "direction": 1,
  "effective_spread": 0.060000000000002274,
  "effective_spread_relative": 0.0005997600959616381,
  "effective_spread_bps": 5.997600959616381
}

Showing 14 of 17 fields.

Other exports#

This module also exports quotedSpread, realizedSpread, 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#

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

Calculation flow#

Effective Spread validation flow
flowchart LR
    A["Question: How far did a signed execution occur from the contemporaneous quote midpoint?"] --> B["Freeze instrument, scope, clock, units, and variant"]
    B --> C["Validate Effective Spread inputs"]
    C --> D{"Eligible and synchronized?"}
    D -- "No" --> E["Reject with topic-specific reason"]
    D -- "Yes" --> F["Apply the frozen Effective 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.

Read the article →

References#

  • SEC Rule 605 adopting release — 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
  • Rule 605 staff FAQ transitionU.S. Securities and Exchange Commission, Division of Trading and Markets staff

The rest of the Liquidity and Spreads family#