fintech-algorithms

Lee-Ready Trade Signing

Install and import

bash
npm install fintech-algorithms
ts
import { leeReady } from "fintech-algorithms/market-microstructure/trade-classification/lee-ready-trade-signing";

Signature

leeReady(data, config)

The standard hybrid: quote test where the trade is away from the midpoint, tick test at it. The classification most empirical microstructure results are built on, so reproducing them requires this rule specifically.

Parameters

NameTypeNotes
dataClassificationInputTrades with prices, and where the rule needs them, the prevailing quotes.
configClassificationConfigTolerances and tie-breaking rules. Trades exactly at a quote or unchanged in price are the cases where classifiers differ, so the tie rule is part of the contract.

Returns

{ classifications, summary, diagnostics }

Per-trade sign with the rule that produced it, plus counts of the unclassifiable cases. Lee-Ready disagrees with its siblings on exactly those, and hiding them would hide the disagreement.

Errors

  • When required quote data is absent for a rule that needs it — reported per trade rather than thrown

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

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

data
{
  "trades": [
    {
      "id": "T001",
      "sequence": 1,
      "session": "S1",
      "event_time_ms": 1000,
      "available_time_ms": 1025,
      "price": 100.01,
      "size": 100,
      "status": "valid",
      "condition": "regular"
    },
    {
      "id": "T002",
      "sequence": 2,
      "session": "S1",
      "event_time_ms": 2000,
      "available_time_ms": 2025,
      "price": 99.99,
      "size": 125,
      "status": "valid",
      "condition": "regular"
    },
    {
      "id": "T003",
      "sequence": 3,
      "session": "S1",
      "event_time_ms": 3000,
      "available_time_ms": 3025,
      "price": 100,
      "size": 150,
      "status": "valid",
      "condition": "regular"
    }
  ],
  "quotes": [
    {
      "id": "Q001",
      "sequence": 1,
      "event_time_ms": 500,
      "available_time_ms": 520,
      "bid": 99.99,
      "ask": 100.01,
      "status": "valid",
      "source": "SYNTH-NBBO"
    },
    {
      "id": "Q002",
      "sequence": 2,
      "event_time_ms": 1500,
      "available_time_ms": 1520,
      "bid": 99.99,
      "ask": 100.01,
      "status": "valid",
      "source": "SYNTH-NBBO"
    },
    {
      "id": "Q003",
      "sequence": 3,
      "event_time_ms": 2500,
      "available_time_ms": 2520,
      "bid": 99.99,
      "ask": 100.01,
      "status": "valid",
      "source": "SYNTH-NBBO"
    }
  ]
}
config
{
  "quote_lag_ms": 0,
  "midpoint_tolerance": 0,
  "zero_tick_mode": "carry"
}

Call

leeReady(data, config)

Returns

object with 20 fields: state, method, trace, total_valid, classified_count, unknown_count, buy_count, sell_count, …

{
  "state": "ok",
  "method": "lee-ready",
  "trace": [
    {
      "id": "T001",
      "sequence": 1,
      "event_time_ms": 1000,
      "price": 100.01,
      "volume": 100,
      "sign": 1,
      "side": "buy",
      "reason": "above-midpoint",
      "rule": "quote",
      "midpoint": 100,
      "quote_id": "Q001",
      "cumulative_signed_volume": 100
    },
    {
      "id": "T002",
      "sequence": 2,
      "event_time_ms": 2000,
      "price": 99.99,
      "volume": 125,
      "sign": -1,
      "side": "sell",
      "reason": "below-midpoint",
      "rule": "quote",
      "midpoint": 100,
      "quote_id": "Q002",
      "cumulative_signed_volume": -25
    },
    {
      "id": "T003",
      "sequence": 3,
      "event_time_ms": 3000,
      "price": 100,
      "volume": 150,
      "sign": 1,
      "side": "buy",
      "reason": "midpoint-fallback:uptick",
      "rule": "tick-fallback",
      "midpoint": 100,
      "quote_id": "Q003",
      "cumulative_signed_volume": 125
    }
  ],
  "total_valid": 60,
  "classified_count": 60,
  "unknown_count": 0,
  "buy_count": 40,
  "sell_count": 20,
  "buy_volume": 6925,
  "sell_volume": 3425,
  "unknown_volume": 0,
  "signed_volume": 3500,
  "total_volume": 10350,
  "coverage": 1
}

Showing 14 of 20 fields.

Other exports

This module also exports tickTest, quoteTest, studentTCdf, bulkVolumeClassification, 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

Lee-Ready Trade Signing — calculation map
Lee-Ready Trade Signing — decision boundary
Lee-Ready Trade Signing — failure boundary
Lee-Ready Trade Signing — scenario matrix
Lee-Ready Trade Signing — 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