Lee-Ready Trade Signing
Install and import#
npm install fintech-algorithmsimport { 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#
| Name | Type | Notes |
|---|---|---|
data | ClassificationInput | Trades with prices, and where the rule needs them, the prevailing quotes. |
config | ClassificationConfig | Tolerances 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#
{
"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"
}
]
}{
"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#
Calculation flow#
Lee-Ready Trade Signing Calculation Flow
flowchart LR
A["Final synthetic records"] --> B["Order by event time and sequence"]
B --> C["Apply status and condition filters"]
C --> D["Enforce availability and causal reference"]
D --> E["Run Lee-Ready Trade Signing"]
E --> F["Sign or fractional volume"]
F --> G["Reason code and trace"]
G --> H["Coverage and imbalance"]
H --> I["Sensitivity comparison"]
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#
- Inferring Trade Direction from Intraday Data — Charles M. C. Lee and Mark J. Ready
- Daily TAQ Client Specification — NYSE / ICE Data Services
- Nasdaq TotalView-ITCH 5.0 Specification — Nasdaq
- Liquidity Measurement Problems in Fast, Competitive Markets — Craig W. Holden and Stacey Jacobsen