# Extended Kalman Filter

`D09-F04-A02` · Statistical Time Series → State and Regime Models · archetype `record-transform` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/statistical-time-series/state-and-regime-models/extended-kalman-filter/
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 { runFilter } from "fintech-algorithms/statistical-time-series/state-and-regime-models/extended-kalman-filter";
```

## Signature

```ts
runFilter(observations, config)
```

The Kalman filter for non-linear systems, linearised at each step. The approximation is local, so strong non-linearity can make it diverge — quietly, while still producing plausible-looking numbers.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `observations` | `number[]` | yes | Noisy observations. |
| `config` | `{ a, b, c, q, r, initial_mean, initial_variance }` | yes | `a`, `b` and `c` parameterise the non-linear transition and observation functions; `q` and `r` are the noise variances. |

## Returns

`{ …per-step estimates }[]`

Per-step predicted and filtered estimates with the gain, as for the linear filter.

## Errors

- When r is not positive — throws

## Complexity

Time `O(n)`, space `O(n)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`observations`:

```json
[0.1740564489, 0.7180957323, 0.0365723689]
```

`config`:

```json
{
  "a": 0.9,
  "b": 0.22,
  "c": 0.04,
  "q": 0.06,
  "r": 0.49,
  "initial_mean": 0,
  "initial_variance": 1.5
}
```

### Call

```ts
runFilter(observations, config)
```

### Returns

object with 1 field: 2

```json
{
  "2": {
    "index": 2,
    "transition_jacobian": 1.0979025313193456,
    "measurement_jacobian": 1.040234775932769,
    "predicted_mean": 0.5029346991596126,
    "predicted_variance": 0.36799793432466277,
    "predicted_observation": 0.5130524316243634,
    "innovation": -0.47648006272436344,
    "innovation_variance": 0.8882062919307445,
    "kalman_gain": 0.4309857431023305,
    "filtered_mean": 0.2975785852529078,
    "filtered_variance": 0.20301476071185573
  }
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

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/statistical-time-series/state-and-regime-models/extended-kalman-filter/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/state-and-regime-models/extended-kalman-filter/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/statistical-time-series/llms.txt
