# Unscented Kalman Filter

`D09-F04-A03` · 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/unscented-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/unscented-kalman-filter";
```

## Signature

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

Propagates a set of deterministically chosen sigma points through the non-linearity instead of linearising it. More robust than the extended filter for the same cost order, and the usual answer when the EKF diverges.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `observations` | `number[]` | yes | Noisy observations. |
| `config` | `{ a, b, c, q, r, alpha, beta, kappa, initial_mean, initial_variance }` | yes | `alpha`, `beta` and `kappa` control the sigma-point spread. `beta = 2` is optimal for Gaussian state distributions; `alpha` is normally small. |

## Returns

`{ …per-step estimates }[]`

Per-step estimates with the sigma-point statistics behind them.

## Errors

- When the sigma-point parameters produce a non-positive-definite covariance — 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,
  "alpha": 1,
  "beta": 2,
  "kappa": 0,
  "initial_mean": 0,
  "initial_variance": 1.5
}
```

### Call

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

### Returns

object with 1 field: 2

```json
{
  "2": {
    "index": 2,
    "sigma_left": -0.0995315114397366,
    "sigma_center": 0.4049746384367636,
    "sigma_right": 0.9094807883132638,
    "predicted_mean": 0.4403571228780741,
    "predicted_variance": 0.36471237345744356,
    "predicted_measurement": 0.46270219364315,
    "innovation": -0.42612982474315003,
    "innovation_variance": 0.8812872395279235,
    "kalman_gain": 0.4284195343347881,
    "filtered_mean": 0.2577947817954489,
    "filtered_variance": 0.20295800755826507
  }
}
```

## 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/unscented-kalman-filter/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/state-and-regime-models/unscented-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
