Detecting regime shifts with Bayesian online changepoints
A rolling estimate adapts gradually when a return series changes regime; a fixed-window fit can react faster but discards older data abruptly. Bayesian online changepoint detection (BOCPD) offers another view: after each observation, maintain probabilities for how long the current regime has lasted. A sudden surprise shifts probability toward a recent change while preserving uncertainty about when it occurred.
Surprise raises the changepoint probability
Bayes update with a 2% prior hazard. A likelihood ratio of one leaves the prior unchanged.
Track the run length
Let be an observation such as a standardized return, absolute return, spread, or order-flow statistic. Define run length as the number of observations since the most recent changepoint. The filter maintains
This is a distribution over possible regime ages, not a hard label. The probability of a change at time is the mass at ; a trader or risk system can use that probability, or the entire run-length distribution, downstream.
Update growth and reset paths
Suppose is the hazard: the probability of a changepoint after a run of length . Let be the predictive probability of the new observation under the hypothesis that the current segment has age . For a candidate run that continues, its unnormalized probability grows from the previous run length:
All candidate runs can also reset to zero:
The predictive likelihood rewards run-length hypotheses that explain the new data; the hazard trades that evidence against the prior frequency of regime changes. With a constant hazard , the prior expected segment length is approximately observations. A larger expected length makes the filter less eager to declare a new regime.
For conjugate segment models, the predictive distribution for each run length can be updated recursively from sufficient statistics. With a Gaussian model and a conjugate prior, for example, each candidate segment carries its own posterior for the mean and variance. The algorithm is causal: it uses data observed through and does not need future observations to revise the current changepoint probability.
Applying the filter to market data
For daily risk monitoring, one option is to model returns with a heavy-tailed segment likelihood and inspect . A spike can indicate a shift in the return distribution, but a single large observation can also trigger it. For volatility regimes, feed the model a transformed series such as absolute or squared standardized returns, or make segment variance a latent parameter. For execution, aggregated signed order flow or spread data can drive online updates to a market-impact model.
A practical workflow:
- Choose the quantity whose distribution may change: raw returns, innovations after a volatility filter, liquidity measures, or model residuals.
- Specify the within-segment likelihood and predictive update. Account for heavy tails or dependence if those features matter.
- Choose and stress-test a hazard model using plausible regime durations; avoid tuning it to a single historical break.
- Process observations in timestamp order and store the full posterior or a controlled approximation to it.
- Evaluate detection delay, false alarms, and downstream forecast or risk performance out of sample.
A changepoint probability is not a trading signal
A high posterior probability of a recent change says that the assumed data-generating model fits better after a reset. It does not say which direction prices will move, whether the shift will persist, or whether a strategy should trade. Use it as an input to forecasts or risk limits, with costs and decision thresholds evaluated separately.
Computation and modeling limits
In the exact filter, the number of run-length hypotheses grows with the data stream. Implementations commonly truncate negligible posterior mass, cap the maximum run length, or approximate the state distribution. The discarded mass and truncation rule should be monitored because an overly aggressive cap can erase evidence for long stable regimes.
The classic formulation assumes observations are conditionally independent within a segment given segment parameters. Financial returns can retain serial dependence, volatility clustering, and changing tail behavior within regimes. Prewhitening, richer segment models, or online autoregressive extensions may help, but they add estimation risk. BOCPD also detects distributional changes only relative to the likelihood and hazard supplied; misspecification can produce late alarms or repeated false ones.
Common mistakes
- Reading the reset probability as certainty that a structural break occurred.
- Setting the hazard from the same short sample used to judge detection quality.
- Feeding clustered raw returns to an i.i.d. segment model and attributing volatility bursts to mean changes.
- Ignoring timestamp alignment, stale observations, or revisions in a live data pipeline.
- Comparing an online alarm with an offline segmentation that used future observations as if they had equal information.
Practice
HazardUnder a constant hazard of 1/100 per observation, what is the prior expected segment length, approximately?Show answer
About 100 observations. This is a prior scale for segment duration, not a guaranteed interval between detected changes.
PosteriorThe posterior mass at run length zero rises after a large return. What does the filter conclude?Show answer
Given its likelihood and hazard assumptions, a recent reset has become more plausible. It does not infer the direction or persistence of the next return.
EvaluationWhy should an online detector be assessed by detection delay as well as classification accuracy?Show answer
An alarm that eventually identifies a historical break may arrive too late to help a live risk or execution decision; delay and false-alarm costs reflect the actual use.
Further reading: Adams and MacKay (2007), Bayesian Online Changepoint Detection; Tsaknaki, Lillo, and Mazzarisi (2025), Bayesian Autoregressive Online Change-Point Detection with Time-Varying Parameters.