Bayesian Online Changepoint Detection
Bayesian online changepoint detection (BOCPD) turns the vague impression that “the regime changed” into a sequential posterior over how long the current regime has lasted. At each new observation it updates a distribution over the run length—the number of observations since the most recent break—using a predictive model and a hazard rate for a new break.
For return observation xt, BOCPD maintains p(rt | x_1:t). A constant hazard H says a regime ends with probability 1/lambda each period. Existing run lengths grow by one, weighted by their predictive likelihood; a new run length of zero receives the hazard probability. The posterior is normalized after every step.
| Component | Role | Trading interpretation |
|---|---|---|
| Predictive model | Expected observation under a run | return, volatility, spread, or IC process |
| Hazard | Prior break frequency | expected regime duration |
| Run length | Time since latest break | confidence in continuity |
| Posterior | Evidence-weighted state | trigger or model-weight input |
import numpy as np
def update(log_prob, log_pred, hazard):
# log_prob[r]: previous run-length posterior; log_pred[r]: predictive likelihood
growth = log_prob + log_pred + np.log1p(-hazard)
reset = np.logaddexp.reduce(log_prob + log_pred + np.log(hazard))
out = np.r_[reset, growth]
return out - np.logaddexp.reduce(out) # normalize in log space
The predictive likelihood is the model. A normal distribution with unknown mean and variance admits efficient conjugate updates but can overreact to a single fat-tailed return. Student-t observations, robust variance estimators, or applying BOCPD to realized volatility and factor residuals are often safer. A change in mean return is notoriously difficult to identify; a change in volatility or correlation is usually more observable.
Choose actions, not only alarms
A high probability of reset is not automatically a buy or sell signal. It is evidence that the old parameter estimates may be stale. Useful responses include reducing leverage, shortening estimator windows, switching model weights, increasing execution caution, or escalating a review. Calibrate decisions on historical utility and false-alarm cost.
| Observation | Possible break | Sensible response |
|---|---|---|
| volatility jump | risk regime | reduce gross exposure |
| factor residual shift | alpha decay | downweight model |
| spread widening | liquidity regime | lower participation |
| correlation surge | diversification failure | tighten portfolio stress limits |
Hazard selection has real consequences. A short expected duration creates frequent resets and may chase noise; a long duration makes genuine breaks slow to detect. Run sensitivity analysis across plausible lambda values and report detection delay and false-alarm rate by known historical events. Do not tune it solely to maximize backtest performance—this is another parameter search requiring avoiding overfitting in trading.
BOCPD differs from change-point detection in trading methods based on fixed retrospective tests: it is causal and maintains uncertainty about the break location. It also differs from regime detection with HMMs: an HMM models recurring latent states, whereas BOCPD models episodic resets. A combined system can use BOCPD to detect structural changes and an HMM to classify recurring market conditions afterward.
Operationally, store the full run-length posterior and inputs with each alert. It is otherwise impossible to distinguish a justified reset from an outlier-induced false alarm during a later review. Backtest the policy that consumes alerts—including its trading delay, risk reduction, and recovery rule—rather than reporting only detection accuracy.
Key takeaways
- BOCPD maintains a real-time posterior over time since the last distributional break.
- Its hazard rate encodes a prior belief about regime duration.
- Robust predictive models matter more than elegant recursion in fat-tailed markets.
- Treat changepoints as risk-management information, not automatic trading directions.
- Validate alert policies with delay, false-alarm, and economic-cost analysis.
