fintech-algorithms

Liquidity-Wall and Concentration Detection

Install and import

bash
npm install fintech-algorithms
ts
import { liquidityWallConcentration } from "fintech-algorithms/market-microstructure/market-depth-analytics/liquidity-wall-and-concentration-detection";

Signature

liquidityWallConcentration(levelsRaw, multipleRaw, minShareRaw, thresholdRaw)

Finds levels holding disproportionate size — the 'walls' that act as short-term barriers. Worth treating with suspicion: a wall that disappears the moment price approaches it was never liquidity.

Parameters

NameTypeNotes
levelsRawLevel[]Book levels to examine.
multipleRawnumberHow many times the average level size counts as a wall.
min: 0
minShareRawnumberMinimum share of total depth a level must hold.
min: 0 · max: 1
thresholdRawnumberConcentration threshold above which the book is flagged as concentrated.
min: 0

Returns

{ walls, concentration, flagged, … }

Detected walls with the concentration measure for the book as a whole.

Errors

  • When minShareRaw falls outside 0…1 — throws

Complexity: time O(levels), space O(walls).

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

levelsRaw
[
  {
    "price": 100.01,
    "quantity": 100
  },
  {
    "price": 100.02,
    "quantity": 110
  },
  {
    "price": 100.03,
    "quantity": 450
  }
]

Showing 3 of 5 elements.

multipleRaw
2.5
minShareRaw
0.3
thresholdRaw
0.3

Call

liquidityWallConcentration(levelsRaw, multipleRaw, minShareRaw, thresholdRaw)

Returns

object with 13 fields: model, level_count, total_depth, median_level_quantity, hhi_fraction, effective_level_count, largest_level_index, largest_level_share, …

{
  "model": "level-share-concentration-and-wall-screen",
  "level_count": 5,
  "total_depth": 900,
  "median_level_quantity": 120,
  "hhi_fraction": 0.3128395061728395,
  "effective_level_count": 3.196527229676401,
  "largest_level_index": 2,
  "largest_level_share": 0.5,
  "walls": [
    {
      "level_index": 2,
      "price": 100.03,
      "quantity": 450,
      "depth_share": 0.5,
      "median_multiple": 3.75
    }
  ],
  "wall_multiple": 2.5,
  "minimum_share": 0.3,
  "concentration_threshold": 0.3,
  "state": "wall-detected"
}

Other exports

This module also exports cumulativeDepth, topNDepthImbalance, depthAtDistanceProfile, expectedFillPrice, sweepCostAndSlippage, depthDepletionReplenishment, marketDepthHeatmap, 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

Liquidity-Wall and Concentration Detection — 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