fintech-algorithms

Tick Test

Install and import

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

Signature

tickTest(data, config)

Signs a trade buyer- or seller-initiated by comparing its price with the previous trade. The cheapest classifier and the least accurate — it needs no quote data, which is exactly why it is still used on historical tapes that have none.

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. Tick 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,
      "size": 100,
      "status": "valid",
      "condition": "regular"
    },
    {
      "id": "T002",
      "sequence": 2,
      "session": "S1",
      "event_time_ms": 2000,
      "available_time_ms": 2025,
      "price": 100.01,
      "size": 125,
      "status": "valid",
      "condition": "regular"
    },
    {
      "id": "T003",
      "sequence": 3,
      "session": "S1",
      "event_time_ms": 3000,
      "available_time_ms": 3025,
      "price": 100.01,
      "size": 150,
      "status": "valid",
      "condition": "regular"
    }
  ]
}
config
{
  "zero_tick_mode": "carry",
  "reset_on_session": true
}

Call

tickTest(data, config)

Returns

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

{
  "state": "ok",
  "method": "tick-test",
  "trace": [
    {
      "id": "T001",
      "sequence": 1,
      "event_time_ms": 1000,
      "price": 100,
      "volume": 100,
      "sign": 0,
      "side": "unknown",
      "reason": "no-prior-trade",
      "reference_price": null,
      "cumulative_signed_volume": 0
    },
    {
      "id": "T002",
      "sequence": 2,
      "event_time_ms": 2000,
      "price": 100.01,
      "volume": 125,
      "sign": 1,
      "side": "buy",
      "reason": "uptick",
      "reference_price": 100,
      "cumulative_signed_volume": 125
    },
    {
      "id": "T003",
      "sequence": 3,
      "event_time_ms": 3000,
      "price": 100.01,
      "volume": 150,
      "sign": 1,
      "side": "buy",
      "reason": "zero-uptick",
      "reference_price": 100.01,
      "cumulative_signed_volume": 275
    }
  ],
  "total_valid": 60,
  "classified_count": 58,
  "unknown_count": 2,
  "buy_count": 23,
  "sell_count": 35,
  "buy_volume": 3875,
  "sell_volume": 6200,
  "unknown_volume": 275,
  "signed_volume": -2325,
  "total_volume": 10350,
  "coverage": 0.9666666667
}

Showing 14 of 16 fields.

Other exports

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

Tick Test — calculation map
Tick Test — decision boundary
Tick Test — failure boundary
Tick Test — scenario matrix
Tick Test — 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