fintech-algorithms

Bayesian Change-Point Detection

Install and import

bash
npm install fintech-algorithms
ts
import { runFilter } from "fintech-algorithms/statistical-time-series/state-and-regime-models/bayesian-change-point-detection";

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.3275053489,
  0.2452664583,
  0.224748597,
  -0.4831667396,
  -0.3522213433,
  0.2466719749
]

Showing 6 of 160 elements.

config
{
  "hazard": 0.025,
  "observation_variance": 0.36,
  "prior_mean": 0,
  "prior_variance": 4
}

Call

runFilter(observations, config)

Returns

array of 160 objects

[
  {
    "index": 0,
    "change_probability": 0.025000000000000012,
    "map_run_length": 1,
    "expected_run_length": 0.9750000000000001,
    "active_hypotheses": 2,
    "map_mean": -0.3004636228440367,
    "log_predictive_density": -1.6674749923390564
  },
  {
    "index": 1,
    "change_probability": 0.012415673831408902,
    "map_run_length": 2,
    "expected_run_length": 1.9504790441829676,
    "active_hypotheses": 3,
    "map_mean": -0.0393487514832536,
    "log_predictive_density": -0.9621570121513477
  },
  {
    "index": 2,
    "change_probability": 0.00942784148480788,
    "map_run_length": 3,
    "expected_run_length": 2.924161240458136,
    "active_hypotheses": 4,
    "map_mean": 0.04611964608414239,
    "log_predictive_density": -0.6857585614486436
  }
]

Showing 3 of 160 elements.

Diagrams

Bayesian Change-Point Detection — diagnostic scorecard
Bayesian Change-Point Detection — failure boundary
Bayesian Change-Point Detection — family handoff
Bayesian Change-Point Detection — scenario comparison
Bayesian Change-Point Detection — state update
Bayesian Change-Point Detection — uncertainty ledger

Calculation flow

Bayesian Change-Point Detection 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