fintech-algorithms

Kyle Lambda

Install and import

bash
npm install fintech-algorithms
ts
import { kyleLambda } from "fintech-algorithms/market-microstructure/order-flow-and-impact/kyle-lambda";

Signature

kyleLambda(inputRows, volumeTransform, intercept)

The price-impact coefficient from regressing price change on signed order flow. Lambda *is* the illiquidity parameter in Kyle's model — higher means each unit of flow moves price more.

Parameters

NameTypeNotes
inputRowsRow[]Interval observations of price change and signed volume.
volumeTransformstringHow signed volume enters the regression — raw, or square-rooted for the concave impact many studies find.
interceptbooleanWhether to fit an intercept. Theory says zero; fitting one and finding it non-zero is diagnostic.

Returns

{ lambda, r_squared, intercept, observations, … }

The coefficient with its fit quality — a lambda from a regression that explains nothing is a number, not a measurement.

Errors

  • When fewer than two observations, or zero variance in signed volume — throws

Complexity: time O(n), 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

inputRows
[
  {
    "id": "K001",
    "interval_end": 0,
    "signed_volume_k": -8.8,
    "mid_change_bps": -3.756
  },
  {
    "id": "K002",
    "interval_end": 1,
    "signed_volume_k": 4.8,
    "mid_change_bps": 2.196
  },
  {
    "id": "K003",
    "interval_end": 2,
    "signed_volume_k": 0,
    "mid_change_bps": 0.08
  }
]

Showing 3 of 60 elements.

volumeTransform
"linear"
intercept
true

Call

kyleLambda(inputRows, volumeTransform, intercept)

Returns

object with 10 fields: model, state, volume_transform, intercept, observation_count, alpha_bps, lambda_bps_per_regressor_unit, r_squared, …

{
  "model": "empirical-kyle-lambda",
  "state": "estimated",
  "volume_transform": "linear",
  "intercept": true,
  "observation_count": 60,
  "alpha_bps": 0.1008250803,
  "lambda_bps_per_regressor_unit": 0.4210091524,
  "r_squared": 0.9980824794,
  "residual_std_bps": 0.1004292969,
  "trace": [
    {
      "id": "K001",
      "index": 0,
      "signed_volume_k": -8.8,
      "regressor": -8.8,
      "mid_change_bps": -3.756,
      "predicted_change_bps": -3.6040554607,
      "residual_bps": -0.1519445393,
      "side": "negative-impact",
      "reason": "linear"
    },
    {
      "id": "K002",
      "index": 1,
      "signed_volume_k": 4.8,
      "regressor": 4.8,
      "mid_change_bps": 2.196,
      "predicted_change_bps": 2.1216690117,
      "residual_bps": 0.0743309883,
      "side": "positive-impact",
      "reason": "linear"
    },
    {
      "id": "K003",
      "index": 2,
      "signed_volume_k": 0,
      "regressor": 0,
      "mid_change_bps": 0.08,
      "predicted_change_bps": 0.1008250803,
      "residual_bps": -0.0208250803,
      "side": "positive-impact",
      "reason": "linear"
    }
  ]
}

Other exports

This module also exports orderFlowImbalance, queueImbalance, hasbrouckPriceImpact, pin, vpin, runTopic. 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

Kyle Lambda — calculation map
Kyle Lambda — decision boundary
Kyle Lambda — failure boundary
Kyle Lambda — scenario matrix
Kyle Lambda — worked example

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