# Previous-Tick Interpolation

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

Full page: https://docs.thefintechbuilder.com/market-data-engineering/time-synchronization/previous-tick-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 { previousTick } from "fintech-algorithms/market-data-engineering/time-synchronization/previous-tick-interpolation";
```

## Signature

```ts
previousTick(observations, requests, maxStalenessMs)
```

Samples a series onto a grid by carrying the last value known *at that moment* forward. The only interpolation that is safe on live data: it never uses a value that had not yet arrived.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `observations` | `Observation[]` | yes | Observations carrying both `event_time` and `available_time`, which is what allows the as-of rule to be applied honestly. |
| `requests` | `{ grid_time: string; query_time: string }[]` | yes | The grid points to sample, each with the knowledge time the answer must respect. |
| `maxStalenessMs` | `number` | yes | How old a carried-forward value may be before the sample is reported unusable rather than silently stale. · min: 0 |

## Returns

`Sample[]` · length same-as-input

One sample per request with the value used, its age, and whether the staleness budget was met.

## Errors

- When maxStalenessMs 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

`observations`:

```json
[
  {
    "instrument": "A",
    "event_time": "2026-01-02T14:30:00.100Z",
    "available_time": "2026-01-02T14:30:00.180Z",
    "revision": 0,
    "value": 100
  },
  {
    "instrument": "A",
    "event_time": "2026-01-02T14:30:00.100Z",
    "available_time": "2026-01-02T14:30:01.400Z",
    "revision": 1,
    "value": 99.8
  },
  {
    "instrument": "A",
    "event_time": "2026-01-02T14:30:02.200Z",
    "available_time": "2026-01-02T14:30:02.260Z",
    "revision": 0,
    "value": 100.4
  }
]
```

Showing 3 of 5 elements.

`requests`:

```json
[
  {
    "grid_time": "2026-01-02T14:30:00.000Z",
    "query_time": "2026-01-02T14:30:00.000Z"
  },
  {
    "grid_time": "2026-01-02T14:30:01.000Z",
    "query_time": "2026-01-02T14:30:01.000Z"
  },
  {
    "grid_time": "2026-01-02T14:30:01.000Z",
    "query_time": "2026-01-02T14:30:02.000Z"
  }
]
```

Showing 3 of 5 elements.

`maxStalenessMs`:

```json
1500
```

### Call

```ts
previousTick(observations, requests, maxStalenessMs)
```

### Returns

array of 10 objects

```json
[
  {
    "instrument": "A",
    "grid_time": "2026-01-02T14:30:00.000Z",
    "query_time": "2026-01-02T14:30:00.000Z",
    "value": null,
    "source_event_time": null,
    "source_available_time": null,
    "source_revision": null,
    "staleness_ms": null,
    "status": "no_history"
  },
  {
    "instrument": "A",
    "grid_time": "2026-01-02T14:30:01.000Z",
    "query_time": "2026-01-02T14:30:01.000Z",
    "value": 100,
    "source_event_time": "2026-01-02T14:30:00.100Z",
    "source_available_time": "2026-01-02T14:30:00.180Z",
    "source_revision": 0,
    "staleness_ms": 900,
    "status": "carried"
  },
  {
    "instrument": "A",
    "grid_time": "2026-01-02T14:30:01.000Z",
    "query_time": "2026-01-02T14:30:02.000Z",
    "value": 99.8,
    "source_event_time": "2026-01-02T14:30:00.100Z",
    "source_available_time": "2026-01-02T14:30:01.400Z",
    "source_revision": 1,
    "staleness_ms": 900,
    "status": "carried"
  }
]
```

Showing 3 of 10 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/previous-tick-interpolation/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-data-engineering/time-synchronization/previous-tick-interpolation/impl.ts
- Standalone repository: https://github.com/IslamBaraka90/Fintech-Previous-Tick-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
