Apr 10
Why a Good Strategy Suddenly Stops Working: Detecting Market Regime Change
A good strategy does not usually break all at once. It runs clean for a long stretch, and then, with no single bad day you can point to, it just stops working. The win rate slips, the average winner gets thinner, and a drawdown that used to recover on its own is still open long after it should have turned. Nothing in the code changed — the entry logic, the exit logic, the position sizing are exactly what they were when the strategy first went live. What changed is the market underneath it, and by the time the equity curve makes that obvious, you have already paid tuition for the lesson.
Every systematic trader eventually asks the same question when a good strategy turns bad: is this an ordinary losing streak, or has the ground itself shifted? The two look identical from inside a drawdown — a string of red trades is a string of red trades — but they call for opposite responses. A losing streak is the noise a strategy was built to survive. A regime change is a different market wearing the same ticker symbol. Treat the second as the first and you will hold on well past the point where holding on made sense.
A market regime is not a mood; it is a persistent set of conditions — trending or ranging, quiet or violent, one correlation structure between assets or another — that holds long enough to leave its fingerprint on every strategy built during it. Every strategy, whether designed by hand or generated with an optimiser, is implicitly fitted to the regime it was built and tested in. That is not a flaw you can engineer away; it is simply what fitting a model to historical data means. The honest question is not whether your strategy is regime-dependent — they all are, to some degree — but whether you will know when the regime it depends on has ended.
The goal, then, is to detect the shift statistically and close to real time, rather than reconstructing it after the fact from a drawdown report. Over the years I have settled on four detectors that I build as coding-base indicators in StrategyQuant X and run alongside — not inside — the strategies I care about. Two ask whether the statistical character of returns has changed; two ask whether the shape of price action over time has changed. Running any of them is a few lines of code. Deciding what their output means for your position size is the part that actually matters.
First, a way to think about it
Before the detail, it helps to sort the four into two families, because they are answering different questions:
- Distributional tests — they set aside when each return happened and ask whether a recent window of returns still looks like it was drawn from the same underlying distribution as a reference window. This attacks drift in the statistical character of returns — volatility, skew, tail risk — even when there is no single dramatic event to point to.
- Sequential and shape tests — they keep time intact and ask whether something changed at an identifiable point, or whether the current path still resembles a reference path. This attacks drift in the behaviour of price over time and, unlike the distributional tests, can often say roughly when the change began rather than only that it happened.
A complete read needs both lenses. A distributional test can tell you the water has changed temperature without telling you when it started to change; a sequential test can pinpoint the moment without always telling you how large the change really is.
1. Kolmogorov–Smirnov test — has the shape of returns changed?
What it defends against: mistaking a change in volatility, skew, or tail risk for an ordinary losing streak, because you were only ever watching the average.
The two-sample Kolmogorov–Smirnov (KS) test compares the empirical cumulative distribution functions of two samples — say, a recent window of returns against a reference window drawn from the period the strategy was built on. The cumulative distribution function at any value is the proportion of observations at or below it; plot both curves, and the KS statistic is simply the largest vertical gap between them, wherever along the curve it occurs.
What makes it useful for regime detection is what it does not assume. It makes no claim that returns are normally distributed — which is fortunate, since they rarely are — and it does not compress each window down to a single number such as its mean. It looks at the whole shape of the distribution at once, so a change in volatility, a change in skew, or fatter tails will all show up as a wider gap between the two curves, even when the average return has barely moved. That breadth is also its limitation: a large KS statistic tells you that the distribution has shifted, but not which part of it moved, or by how much. For that, you need the next test.
2. Wasserstein distance — how far did it move, not just whether it moved
What it defends against: treating every distributional shift the KS test flags as equally urgent, when some are trivial and some are severe.
Wasserstein distance — also known, more intuitively, as earth-mover’s distance — measures the minimum amount of work needed to reshape one probability distribution into another, where work is the amount of probability mass moved, multiplied by the distance it is moved. Picture each return distribution as a pile of sand shaped by how often each outcome occurred; Wasserstein distance is the least effort required to shovel one pile into the shape of the other.
The reason I run it alongside the KS test rather than instead of it is that the two are sensitive to different things. KS is driven entirely by the single largest gap between the two cumulative curves — everything else about the distributions is invisible to it. Wasserstein distance instead integrates the displacement across the whole distribution: two samples can share a similar KS statistic while producing quite different Wasserstein distances, depending on how that displaced mass is spread. In practice, KS tells you a change is statistically real; Wasserstein distance tells you whether it is a shrug or a regime you need to respect.
3. CUSUM — catching a slow drift before it becomes a drawdown
What it defends against: a mean shift so gradual that no single day, and no simple glance at a rolling average, ever looks abnormal enough to flag.
CUSUM — cumulative sum — is older than the other three tools here; it comes out of industrial quality control, where the question was whether a production line had quietly drifted out of specification. Applied to a strategy, it works like this: define a baseline from a reference period — the mean return, or the mean trade result — then add each new observation’s deviation from that baseline to a running total. The sum resets toward its floor whenever deviations are small or mixed in sign, but if deviations start leaning consistently one way, it climbs steadily even though no single observation looks extreme on its own. Cross a chosen threshold and CUSUM declares a change point.
What makes this valuable is that it accumulates evidence no single-point test would notice. A small, steady drift in average return is invisible day to day, but it does not hide from a running sum — the deviations keep adding until the drift becomes undeniable, often well before a rolling drawdown chart looks unusual. The cost is a dial you must set deliberately: a low threshold flags drift early but trips on ordinary noise too; a high threshold stays quiet through the noise but gives a real drift longer to run before anything catches it.
4. Dynamic time warping — does today’s price action still move like the pattern you built for?
What it defends against: dismissing a real shift because a naive point-in-time comparison shows nothing unusual, when the pattern is still there, just running at a different tempo.
Dynamic time warping (DTW) measures how similar two time sequences are while letting the time axis of one stretch and compress locally to line up with the other. A plain point-by-point comparison — this day against that day, this bar against that bar — falls apart the moment a pattern that once played out briskly starts playing out slowly, because a straight comparison assumes both sequences move in lockstep. DTW instead finds whichever alignment between the two sequences minimises the total distance between matched points, and reports that minimised distance as the similarity score.
For regime detection, I use it to compare a recent window of price action against reference templates built from clearly labelled stretches of the strategy’s own history — a trending stretch, a range-bound stretch, a volatile stretch — and see which template the current window warps to most cheaply. A low DTW distance to the trending template, for a strategy built on range-bound data, is a structural warning that a simple correlation coefficient would miss entirely, because DTW does not require the two patterns to be marching at the same pace, only to have the same shape.
How to actually use these tests
Running any one of these tests produces a number and, once you set a threshold, a flag. Turning that flag into a decision is where most of the value — and most of the difficulty — actually lives.
- Window size sets what you can see. A short window reacts fast but is noisy, catching real regime changes alongside plenty of false ones. A long window is stable but slow — a real shift has to persist for a while before it outweighs the history behind it. There is no universally correct choice; it has to match the holding period of the strategy you are protecting.
- Every threshold trades false alarms against lag. Tighten it and you catch real shifts earlier, at the cost of reacting to noise that would have passed on its own. Loosen it and the false alarms mostly disappear, at the cost of sitting through more losing trades before the detector agrees anything is wrong.
- Agreement across detectors says more than any single flag. One KS breach on a short window is common and often means nothing. A KS breach, a rising Wasserstein distance, and a CUSUM alarm arriving together is a far stronger statement, because each is picking up a different aspect of the same underlying shift.
None of the four is a crystal ball, and framing them as one would do you a disservice. Any detector sensitive enough to catch a real regime change early is also sensitive enough to occasionally flag a market that was just having a rough patch and would have settled back down on its own. Treat every flag as certainty and you will find yourself standing aside during ordinary wobbles that a trending strategy is supposed to survive — its own quiet way of destroying an edge.
What works better is using these as an overlay, not a switch. When a detector — or better, more than one — flags rising instability, the sensible response is rarely to shut the strategy down outright. It is closer to trusting it less for now: reduce position size, tighten risk, raise the bar for taking a new signal, and let the strategy keep trading at reduced stakes rather than betting everything on one ambiguous reading. If the instability resolves, you have given away comparatively little. If it does not — if the flags persist and sharpen — you have a far stronger case for stepping aside altogether, built with less capital at risk than if you had waited for the drawdown itself to make the case for you.
The point
Regime detection is not a substitute for building a strategy that can survive more than one regime — it is what you fall back on for the shifts you failed to build resilience against. The deeper fix still matters more: test across the widest range of market conditions you can assemble, and be honest about how much of a strategy’s performance depends on the particular stretch of history it was built on. A strategy that only works in one regime will eventually meet a detector telling it so; a strategy built to tolerate several will trip these alarms less often, and survive the ones it does trip.
Used that way — as a second line of defence rather than the first — Kolmogorov–Smirnov, Wasserstein distance, CUSUM, and dynamic time warping earn their keep. None of them will tell you the future. What they will do is shorten the distance between the market changing and you noticing, and that gap, more than any single indicator, is what a drawdown is actually made of.
If one of your strategies has started drifting and you want help telling an ordinary losing streak from a genuine regime change, that is exactly the kind of question I help clients answer.