Price-Source Consensus Check
Install and import
npm install fintech-algorithmsimport { consensus } from "fintech-algorithms/market-data-engineering/data-quality/price-source-consensus-check";Signature
consensus(snapshot, policy)Reconciles quotes from several providers into one defensible price, or refuses to. Serious platforms never trust a single vendor, and two feeds never agree exactly — this is the layer that decides who is right.
Parameters
| Name | Type | Notes |
|---|---|---|
snapshot | { as_of: string; quotes: SourceQuote[] } | One quote per source at a moment in time, each with its own timestamp so staleness is per-source. |
policy | { minimum_independent_sources: number; z_threshold: number; absolute_tolerance: number; maximum_tolerance: number; max_age_ms: number; expected_contract?: string } | minimum_independent_sources is the quorum below which no consensus is declared. z_threshold sets how far from the robust centre a quote may sit before it is an outlier, bounded by absolute_tolerance and maximum_tolerance so the test behaves at both very tight and very wide spreads. max_age_ms excludes stale sources. |
Returns
{ status, reason, consensus_price, inliers, outliers, diagnostics }
A status rather than a bare number: a refusal to price is a legitimate and important outcome, and reason says why.
Errors
- When the policy is internally inconsistent, such as a negative tolerance — throws
Complexity: time O(n log 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
{
"as_of": "2026-07-13T13:30:01.000Z",
"quotes": [
{
"source_id": "A",
"owner_id": "OWNER-A",
"price": 100,
"instrument_id": "SYNTH-USD",
"currency": "USD",
"price_type": "last_trade",
"adjustment": "unadjusted",
"session": "regular",
"event_time": "2026-07-13T13:30:01.000Z"
},
{
"source_id": "B",
"owner_id": "OWNER-B",
"price": 100.01,
"instrument_id": "SYNTH-USD",
"currency": "USD",
"price_type": "last_trade",
"adjustment": "unadjusted",
"session": "regular",
"event_time": "2026-07-13T13:30:01.000Z"
},
{
"source_id": "C",
"owner_id": "OWNER-C",
"price": 100.02,
"instrument_id": "SYNTH-USD",
"currency": "USD",
"price_type": "last_trade",
"adjustment": "unadjusted",
"session": "regular",
"event_time": "2026-07-13T13:30:01.000Z"
}
]
}{
"minimum_independent_sources": 3,
"z_threshold": 3.5,
"absolute_tolerance": 0.03,
"maximum_tolerance": 0.15,
"max_age_ms": 500,
"expected_contract": {
"instrument_id": "SYNTH-USD",
"currency": "USD",
"price_type": "last_trade",
"adjustment": "unadjusted",
"session": "regular"
}
}Call
consensus(snapshot, policy)Returns
object with 6 fields: status, reason, consensus_price, inliers, outliers, diagnostics
{
"status": "consensus",
"reason": "quorum_met",
"consensus_price": 100.01,
"inliers": ["A", "B", "C", "D"],
"outliers": [],
"diagnostics": {
"observed_source_count": 4,
"eligible_independent_source_count": 4,
"minimum_independent_sources": 3,
"excluded": [],
"initial_center": 100.01,
"mad": 0.0049999999999954525,
"robust_scale": 0.007412898443284585,
"adaptive_tolerance": 0.025945144551496047,
"absolute_tolerance": 0.03,
"applied_tolerance": 0.03,
"maximum_tolerance": 0.15,
"zero_mad_policy": "not_applicable",
"comparison_epsilon": 1e-12,
"inlier_independent_source_count": 4
}
}Diagrams
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
- R01 - Median Absolute Deviation — National Institute of Standards and Technology (NIST)
- R02 - Detection of Outliers — NIST/SEMATECH
- R03 - Nasdaq TotalView-ITCH 5.0 — Nasdaq
- R04 - FIX MarketDataSnapshotFullRefresh — FIX Trading Community
- Evidence-role ledger
- Historical-case acceptance criteria