fintech-algorithms

Linear Quote Interpolation

Install and import

bash
npm install fintech-algorithms
ts
import { linearQuoteInterpolation } from "fintech-algorithms/market-data-engineering/time-synchronization/linear-quote-interpolation";

Signature

linearQuoteInterpolation(quotes, targets, maxGapMs)

Interpolates between the quotes either side of a target time. More accurate than carrying forward, and **not causal** — it uses a quote from after the target, so it belongs in research and never in a live path.

Parameters

NameTypeNotes
quotesQuote[]Quotes with event_time, available_time, bid and ask.
targetsTarget[]Times to interpolate at, each with the evaluation time that bounds what may be used.
maxGapMsnumberWidest gap between bracketing quotes that may still be interpolated across.
min: 0

Returns

Sample[] · length same-as-input

One sample per target with both bracketing quotes, the interpolated value, and whether the gap budget was met.

Errors

  • When maxGapMs is negative — throws

Complexity: time O(n + m), space O(m).

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

quotes
[
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "event_time": "2026-01-01T00:00:00.000Z",
    "available_time": "2026-01-01T00:00:00.100Z",
    "bid": 99,
    "ask": 101
  },
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "event_time": "2026-01-01T00:00:02.000Z",
    "available_time": "2026-01-01T00:00:02.120Z",
    "bid": 101,
    "ask": 103
  }
]
targets
[
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "target_time": "2026-01-01T00:00:01.000Z",
    "evaluation_time": "2026-01-01T00:00:01.000Z"
  },
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "target_time": "2026-01-01T00:00:01.000Z",
    "evaluation_time": "2026-01-01T00:00:02.120Z"
  },
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "target_time": "2026-01-01T00:00:00.000Z",
    "evaluation_time": "2026-01-01T00:00:00.000Z"
  }
]

Showing 3 of 5 elements.

maxGapMs
2000

Call

linearQuoteInterpolation(quotes, targets, maxGapMs)

Returns

array of 5 objects

[
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "target_time": "2026-01-01T00:00:01.000Z",
    "evaluation_time": "2026-01-01T00:00:01.000Z",
    "bid": null,
    "ask": null,
    "status": "right_not_available",
    "reason": "right_endpoint_arrives_after_evaluation",
    "interpolated": false,
    "observable": false,
    "left_event_time": "2026-01-01T00:00:00.000Z",
    "right_event_time": "2026-01-01T00:00:02.000Z",
    "left_available_time": "2026-01-01T00:00:00.100Z"
  },
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "target_time": "2026-01-01T00:00:01.000Z",
    "evaluation_time": "2026-01-01T00:00:02.120Z",
    "bid": 100,
    "ask": 102,
    "status": "linear",
    "reason": "both_endpoints_available",
    "interpolated": true,
    "observable": false,
    "left_event_time": "2026-01-01T00:00:00.000Z",
    "right_event_time": "2026-01-01T00:00:02.000Z",
    "left_available_time": "2026-01-01T00:00:00.100Z"
  },
  {
    "instrument": "A",
    "venue": "X",
    "session_id": "S",
    "target_time": "2026-01-01T00:00:00.000Z",
    "evaluation_time": "2026-01-01T00:00:00.000Z",
    "bid": null,
    "ask": null,
    "status": "exact_not_available",
    "reason": "exact_record_arrives_after_evaluation",
    "interpolated": false,
    "observable": false,
    "left_event_time": "2026-01-01T00:00:00.000Z",
    "right_event_time": "2026-01-01T00:00:00.000Z",
    "left_available_time": "2026-01-01T00:00:00.100Z"
  }
]

Showing 3 of 5 elements.

Diagrams

Linear Quote Interpolation — article hero
Linear Quote Interpolation — linear leakage

Calculation flow

Interpolation eligibility and knowledge boundary
flowchart LR
    A["Target plus evaluation cutoff"] --> B{"Exact event?"}
    B -->|Yes| C{"Exact record available?"}
    C -->|No| D["exact_not_available"]
    C -->|Yes| E["exact observed quote"]
    B -->|No| F{"Same-partition bracket?"}
    F -->|No| G["unavailable; no extrapolation"]
    F -->|Yes| H{"Gap within inclusive limit?"}
    H -->|No| I["gap_too_wide"]
    H -->|Yes| J{"Both endpoints available?"}
    J -->|No| K["block at knowledge boundary"]
    J -->|Yes| L["linear derived quote; observable=false"]

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

  • NIST Digital Library of Mathematical Functions, Section 3.3 — National Institute of Standards and Technology
  • SEC Quote Life Report Methodology — U.S. Securities and Exchange Commission, Division of Economic and Risk Analysis
  • Frequently Asked Questions: Rule 605 of Regulation NMS — U.S. Securities and Exchange Commission staff
  • On covariance estimation of non-synchronously observed diffusion processes — Takaki Hayashi and Nakahiro Yoshida
  • RFC 3339: Date and Time on the Internet — IETF; Graham Klyne and Chris Newman
  • Evidence classification