fintech-algorithms

Missing-Bar Gap Classifier

Install and import

bash
npm install fintech-algorithms
ts
import { diagnoseGap } from "fintech-algorithms/market-data-engineering/data-quality/missing-bar-gap-classifier";

Signature

diagnoseGap(row)

Decides why a bar is missing: the session was closed, the instrument was halted, the feed dropped, or a sequence number was skipped. A gap is only a data-quality incident in some of those cases, and treating them alike produces alert fatigue.

Parameters

NameTypeNotes
row{ case_id, scenario, timestamp, bar_state, session_status, halt_status, heartbeat_status, sequence_status }One gap observation with every status the decision depends on, gathered from the layers that can each independently explain it.

Returns

{ classification, decisive_layer, reason, evidence_ids, warnings }

The classification plus which layer settled it, so the diagnosis can be audited rather than trusted.

Errors

  • When a required status field is absent — reported as a warning on the result rather than thrown

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

row
{
  "case_id": "C01",
  "scenario": "canonical",
  "timestamp": "2026-07-13T13:30:00Z",
  "bar_state": "present",
  "session_status": "open",
  "halt_status": "inactive",
  "heartbeat_status": "healthy",
  "sequence_status": "continuous",
  "activity_status": "trades",
  "activity_independent": true,
  "evidence_ids": ["BAR-001", "CAL-2026C"],
  "expected_classification": "present"
}

Call

diagnoseGap(row)

Returns

object with 5 fields: classification, decisive_layer, reason, evidence_ids, warnings

{
  "classification": "present",
  "decisive_layer": "bar",
  "reason": "A validated bar is materialized.",
  "evidence_ids": ["BAR-001", "CAL-2026C"],
  "warnings": []
}

Other exports

This module also exports classifyGap, classifyRows. 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

Missing-Bar Gap Classifier — article hero
Missing-Bar Gap Classifier — gap classification timeline

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