fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Extended Kalman Filter

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#

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#

NameTypeNotes
observationsnumber[]Noisy observations.
config{ a, b, c, q, r, initial_mean, initial_variance }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#

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

Input#

observations
[0.1740564489, 0.7180957323, 0.0365723689]
config
{
  "a": 0.9,
  "b": 0.22,
  "c": 0.04,
  "q": 0.06,
  "r": 0.49,
  "initial_mean": 0,
  "initial_variance": 1.5
}

Call#

runFilter(observations, config)

Returns#

object with 1 field: 2

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

Diagrams#

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

Calculation flow#

Extended 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#

The rest of the State and Regime Models family#