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

Quote Test

Install and import#

bash
npm install fintech-algorithms
ts
import { quoteTest } from "fintech-algorithms/market-microstructure/trade-classification/quote-test";

Signature#

quoteTest(data, config)

Signs a trade by which side of the prevailing midpoint it executed on. More accurate than the tick test where quotes exist, and undefined for trades exactly at the midpoint — which is where the Lee-Ready hybrid earns its place.

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. Quote test 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
}

Call#

quoteTest(data, config)

Returns#

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

{
  "state": "ok",
  "method": "quote-test",
  "trace": [
    {
      "id": "T001",
      "sequence": 1,
      "event_time_ms": 1000,
      "price": 100.01,
      "volume": 100,
      "sign": 1,
      "side": "buy",
      "reason": "above-midpoint",
      "midpoint": 100,
      "bid": 99.99,
      "ask": 100.01,
      "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",
      "midpoint": 100,
      "bid": 99.99,
      "ask": 100.01,
      "quote_id": "Q002",
      "cumulative_signed_volume": -25
    },
    {
      "id": "T003",
      "sequence": 3,
      "event_time_ms": 3000,
      "price": 100,
      "volume": 150,
      "sign": 0,
      "side": "unknown",
      "reason": "midpoint-or-tolerance-band",
      "midpoint": 100,
      "bid": 99.99,
      "ask": 100.01,
      "quote_id": "Q003",
      "cumulative_signed_volume": -25
    }
  ],
  "total_valid": 60,
  "classified_count": 55,
  "unknown_count": 5,
  "buy_count": 35,
  "sell_count": 20,
  "buy_volume": 5950,
  "sell_volume": 3425,
  "unknown_volume": 975,
  "signed_volume": 2525,
  "total_volume": 10350,
  "coverage": 0.9166666667
}

Showing 14 of 19 fields.

Other exports#

This module also exports tickTest, leeReady, 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#

Quote Test — calculation map
Quote Test — decision boundary
Quote Test — failure boundary
Quote Test — scenario matrix
Quote Test — worked example

Calculation flow#

Quote Test 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 Quote Test"]
    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.

Read the article →

References#

The rest of the Trade Classification family#