# Linear Quote Interpolation

`D01-F03-A02` · Market Data Engineering → Time Synchronization · archetype `record-transform` · difficulty 3/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/market-data-engineering/time-synchronization/linear-quote-interpolation/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

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

## Signature

```ts
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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `quotes` | `Quote[]` | yes | Quotes with `event_time`, `available_time`, bid and ask. |
| `targets` | `Target[]` | yes | Times to interpolate at, each with the evaluation time that bounds what may be used. |
| `maxGapMs` | `number` | yes | Widest 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

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`:

```json
[
  {
    "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`:

```json
[
  {
    "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`:

```json
2000
```

### Call

```ts
linearQuoteInterpolation(quotes, targets, maxGapMs)
```

### Returns

array of 5 objects

```json
[
  {
    "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.

## Verification and provenance

Tier: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/market-data-engineering/time-synchronization/linear-quote-interpolation/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-data-engineering/time-synchronization/linear-quote-interpolation/impl.ts
- Standalone repository: https://github.com/IslamBaraka90/Fintech-Linear-Quote-Interpolation-Time-Synchronization-algorithm
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-data-engineering/llms.txt
