You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Feature Engineering for ML (Part 9): Structural Break Tests in Python.
We present a production‑ready implementation of AFML Chapter 17 structural break tests. The module includes Chu-Stinchcombe-White (one-/two-sided), Chow-type DFC, SADF across six models (linear, quadratic, sm poly 1, sm poly 2, sm exp, sm power), plus QADF (q, v) and CADF (q), returning bar-indexed scalar features. We address the book snippets' scaling issues and argument‑order pitfall, and show how a fixed lookback (L=504) bounds SADF cost to O(L²) per bar for regime detection.
Chapter 17 of López de Prado's Advances in Financial Machine Learning opens with a pointed observation. Structural breaks, the transition from one market regime to another, represent some of the best risk-adjusted trading opportunities precisely because most participants are caught off guard. A mean-reverting dynamic that gives way to momentum traps traders who continue to fade breakouts; a trending market that reverts catches traders who held directional positions too long. The actors on the losing side do not immediately recognise their mistake. They hold, they average down, and eventually they are stopped out. It is this forced liquidation that creates the edge. But identifying the transition in real time, rather than in retrospect, requires a formal statistical test.
The module afml.structural_breaks implements two families of such tests. The first, CUSUM tests, measure whether cumulative forecast errors deviate significantly from white noise. The second, explosiveness tests, detect exponential growth or collapse that is inconsistent with a random walk. This article covers both families. It adds two variants not in the original implementation and documents performance problems in the book's Python snippets that make them unusable on realistic series lengths. It closes by developing the chapter's implied link to strategy selection.
Author: Patrick Murimi Njoroge