Skip to main content
Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
What is this? Change point detection tells you when the market regime has shifted - for example, when a stable 50/50 election market suddenly jumps to 70/30 after a debate. Instead of using fixed lookback windows, BOCPD continuously estimates whether the data-generating process has changed, letting you adapt your strategy in real time.

Change Point Detection

Horizon implements Bayesian Online Change Point Detection (BOCPD) using the Adams-MacKay algorithm, entirely in Rust. The detector maintains a full run-length distribution and updates it in O(T) per observation, making it suitable for real-time trading pipelines.

Bayesian BOCPD

Full posterior over run lengths. No fixed window size or threshold tuning required.

O(T) Online Updates

Per-observation update cost is linear in the current run length. Pruning keeps it bounded.

Conjugate Prior

Normal-Inverse-Gamma conjugate prior for Gaussian observations. Exact Bayesian inference.

Pipeline Integration

Drop hz.bocpd_detector() into any pipeline. Injects change probability and run lengths into ctx.params.

BocpdDetector

The core change point detector. It maintains a posterior distribution over run lengths (how many observations since the last change point) and updates it with each new observation.

Constructor

The hazard rate controls sensitivity. A hazard rate of 250 means the detector expects roughly one change point every 250 observations. Lower values make the detector more sensitive (more false positives); higher values make it more conservative.

update()

Process a single observation and update the run-length distribution.
Returns a BocpdResult object.

BocpdResult Type

State Access Methods


Pipeline Integration

hz.bocpd_detector

Creates a pipeline function that runs BOCPD on each tick and injects change point statistics into ctx.params.

Injected Parameters


Examples

Regime Change Detection

Use BOCPD to detect structural breaks in prediction market prices:

BOCPD with Markov Regime Detection

Combine BOCPD with HMM for robust regime classification:

Mathematical Background

BOCPD maintains a distribution over run lengths r_t (the number of observations since the last change point). At each step:
  1. Growth probability: P(r_t = r_{t-1} + 1) — the run continues
  2. Change probability: P(r_t = 0) — a new segment begins
The hazard function H(r) = 1/lambda gives the prior probability of a change point at any given time, where lambda is the hazard rate parameter.
Within each run, observations are modeled as draws from a Gaussian with unknown mean and variance. The Normal-Inverse-Gamma prior (mu0, kappa0, alpha0, beta0) is conjugate, meaning the posterior after observing data has the same parametric form with updated parameters:
  • kappa_n = kappa0 + n
  • mu_n = (kappa0 * mu0 + sum(x)) / kappa_n
  • alpha_n = alpha0 + n/2
  • beta_n = beta0 + 0.5 * (sum(x^2) - kappa_n * mu_n^2 + kappa0 * mu0^2)
The predictive distribution (Student-t) is computed analytically for each run length.
The hazard rate lambda sets the prior expected run length. For prediction markets:
  • lambda = 50-100: Sensitive to rapid shifts (news events, poll releases)
  • lambda = 200-500: Moderate sensitivity for daily regime changes
  • lambda = 1000+: Conservative, only detects major structural breaks
The detector is robust to moderate mis-specification of lambda because the full posterior is maintained.
BOCPD memory grows linearly with the number of observations (one entry per possible run length). For very long streams, the detector automatically prunes low-probability run lengths to keep memory bounded.