fintech-algorithms

Unscented Kalman Filter

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

runFilter(observations, config)

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

observations
[
  0.1740564489,
  0.7180957323,
  0.0365723689,
  -0.3580227464,
  0.3553945738,
  0.4323328535
]

Showing 6 of 160 elements.

config
{
  "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

runFilter(observations, config)

Returns

array of 160 objects

[
  {
    "index": 0,
    "sigma_left": -1.224744871391589,
    "sigma_center": 0,
    "sigma_right": 1.224744871391589,
    "predicted_mean": 0,
    "predicted_variance": 1.7740796257097713,
    "predicted_measurement": 0.07096318502839094,
    "innovation": 0.10309326387160905,
    "innovation_variance": 2.2741511729685184,
    "kalman_gain": 0.7801062861595132,
    "filtered_mean": 0.08042370320694366,
    "filtered_variance": 0.3901089575460621
  },
  {
    "index": 1,
    "sigma_left": -0.5441633263942658,
    "sigma_center": 0.08042370320694366,
    "sigma_right": 0.7050107328081532,
    "predicted_mean": 0.08671868415920991,
    "predicted_variance": 0.536619496516218,
    "predicted_measurement": 0.10848426922715082,
    "innovation": 0.6096114630728492,
    "innovation_variance": 1.0350123867965022,
    "kalman_gain": 0.5220635987934528,
    "filtered_mean": 0.4049746384367636,
    "filtered_variance": 0.2545264552632097
  },
  {
    "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
  }
]

Showing 3 of 160 elements.

Diagrams

Unscented Kalman Filter — diagnostic scorecard
Unscented Kalman Filter — failure boundary
Unscented Kalman Filter — family handoff
Unscented Kalman Filter — scenario comparison
Unscented Kalman Filter — state update
Unscented Kalman Filter — uncertainty ledger

Calculation flow

Unscented Kalman Filter Causal Update Flow
flowchart LR
    A["Filtered state at t-1"] --> B["Predict state at t"]
    B --> C["Read observation available at t"]
    C --> D["Compute evidence or innovation"]
    D --> E["Normalize or gain-weight update"]
    E --> F["Filtered state at t"]
    F --> G["Publish diagnostics"]
    F --> A

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