Research result
Method studyRegime detection with Kalman filters and topology
SPY and GLD · daily2010 – 2026 · 4,136 trading days
A detector that flags changes in how two assets move together, using the shape of their Kalman prediction errors. It flags 18 of 78 windows, and it is not a trading signal.
- Hypothesis tested
- The shape of the joint cloud of Kalman prediction errors can flag structural changes that a plain volatility threshold would miss.
- Result
- Not validated yet. The detector flags 18 of 78 windows. None start in the 2020 crash and two start in the 2022 sell-off, and there are no labelled regime changes to score it against. It is a method, not a trading signal.
- How it was tested
- 78 rolling windows
- Checked against two stress periods
- Windows analysed
- 78
- Windows flagged
- 18
- Window length
- 252 days
- Step
- 50 days
This is the full report behind the summary above. It is a method study, not a trading strategy. The numbers come from the study's notebook, run on SPY and GLD, and the definitions come from the study's written mathematical report.
1. Overview of the pipeline
1.1 The question
Can the shape of the joint cloud of Kalman prediction errors, measured with persistent homology, flag structural changes in how two assets move together that a plain volatility threshold would miss?
The idea behind the study is a change of representation. A simple detector looks at one statistic of one price or return series. This pipeline instead looks at the multiscale shape of the filtered residuals of two assets at the same time. The intention is to react to a change in how the two residual series relate to each other, even when neither series becomes more volatile on its own. This is the study's motivation. It is not a result.
1.2 The five stages
| Stage | What it does | Output |
|---|---|---|
| 1. Baseline detector | Applies a rolling volatility threshold to each asset on its own | A daily flag per asset (defined in Section 2) |
| 2. Signal extraction | Fits a Kalman local linear trend model to each price series | One-step prediction errors, called innovations |
| 3. Topological summary | Treats the paired innovations in a sliding window as a point cloud and computes its persistent homology | A persistence diagram per window |
| 4. Features and threshold | Reduces each diagram to three numbers and flags a window when one is well above its own recent history | A flag per window |
| 5. Checks | Compares flags with two known stress periods, repeats the run on a second pair, and varies the Kalman parameters | Validation, robustness and sensitivity (Sections 8 to 10) |
1.3 Configuration
| Item | Value |
|---|---|
| Pair | SPY and GLD, adjusted daily closing prices |
| Sample | 4,136 trading days from 2010-01-04 |
| Price scaling | Each series divided by its first value before filtering |
| Kalman parameters, both assets | , , |
| Initial state | Level equal to the first price, slope 0, covariance 10 times the identity |
| Window length | 252 trading days |
| Step between windows | 50 trading days |
| Number of windows | 78 |
| Window scaling | Each coordinate set to mean 0 and variance 1 inside each window |
| Homology | Vietoris–Rips filtration, dimensions 0 and 1 |
| Features per window | Maximum lifetime in dimension 0, number of finite features in dimension 0, maximum lifetime in dimension 1 |
| Lookback | 5 windows |
| Threshold multiplier | 2 standard deviations |
| Reported date of a flag | Start date of the flagged window |
| Reference stress periods | 2020-02-15 to 2020-04-15, and 2022-01-01 to 2022-10-31 |
| Second pair, for robustness | QQQ and TLT |
2. The baseline volatility rule
The baseline is the simple detector that the topological one is meant to improve on. For each asset , the daily log return is
The annualized realized volatility over a trailing window of days is the standard deviation of those returns times , which scales a daily figure to a year of about 252 trading days:
A second rolling window of the same length is applied to the volatility series itself. It gives a trailing mean and a trailing standard deviation . The baseline flags a day when volatility is well above its recent typical level:
This rule is applied to each asset alone. The flags of the two assets never depend on each other. So the baseline cannot see a change in the relationship between the two assets, unless that change also shows up as a change in one asset's own variance. This gap is what motivates the topological statistic in Sections 5 and 6.
The study defines this rule but reports no result for it: no flag count and no dates. So this report cannot compare the two detectors.
3. Data
The study uses daily adjusted closing prices, which account for splits and dividends, for SPY (an S&P 500 fund) and GLD (a gold fund), from 2010-01-04 to the date the notebook was run. Days with a missing value in either series are dropped. This leaves a table of 4,136 days and 2 columns.
| Date | GLD | SPY |
|---|---|---|
| 2010-01-04 | 109.80 | 84.80 |
| 2010-01-05 | 109.70 | 85.02 |
| 2010-01-06 | 111.51 | 85.08 |
| 2010-01-07 | 110.82 | 85.44 |
| 2010-01-08 | 111.37 | 85.72 |
The table shows the first five rows, rounded to two decimals. The two series live on very different price scales and move very differently over the sample. SPY rises steadily and ends well above 700. GLD stays below about 200 until 2024 and then rises sharply. This is why each series is divided by its first value before filtering, so both start at 1 and one set of Kalman parameters can serve both.
Exhibit 1
Adjusted closing prices of SPY and GLD, 2010 to 2026

4. Kalman filter: the local linear trend model
4.1 The model
A Kalman filter tracks a hidden quantity through noisy observations. Here the hidden state has two parts: a level and a slope . Each scaled price series (the price divided by its first value) is modelled as
The process noise is and the measurement noise is the single number . In words: tomorrow's level equals today's level plus today's slope, up to noise, and the slope itself drifts as a random walk. The two noise terms are assumed independent of each other, independent over time, and independent of the starting state. Both assets use the same parameters, .
4.2 The recursions
Let and be the mean and covariance of the state at time given the observations up to time . Because the model is linear with Gaussian noise, these are propagated exactly. First the filter predicts:
When arrives, the filter measures how wrong the prediction was. This one-step prediction error is the innovation :
Here is the innovation variance and is the Kalman gain, which says how strongly to correct the state. The update is
The filter starts from the state and a large covariance . This says that little is known at the start about the level and especially the slope.
If the model is right, the innovation is the part of today's value that cannot be predicted linearly from the past. Its average given the past is zero, and innovations at different times are uncorrelated, with variance . This is why the innovation is called the surprise component of a series. A price series is close to a random walk and is strongly autocorrelated. Its innovations are not. Working with innovations removes the dominant trend and leaves the residual structure that the topological stage reads.
Because , , and are constant, the covariance settles to a fixed matrix over time, and the gain settles to a fixed value. The study does not use this shortcut. Its filter runs the full recursion at every step.
The filter runs on each asset separately. The two assets do not interact in this stage. They meet only in the next stage, when the two innovation series are placed side by side.
4.3 The innovations in this study
The filter's first output is zero by construction. On the second day, the prediction is just the starting price, because the starting slope is 0. So the first real innovation equals the one-day price change. For GLD this is 109.70 minus 109.80, or −0.10, which matches the first row below.
| Date | GLD innovation | SPY innovation |
|---|---|---|
| 2010-01-04 | 0.000000 | 0.000000 |
| 2010-01-05 | −0.100006 | 0.224510 |
| 2010-01-06 | 1.859931 | −0.052244 |
| 2010-01-07 | −2.486659 | 0.298823 |
| 2010-01-08 | −0.409535 | 0.123064 |
The report describes the filter on scaled prices. The notebook then multiplies the innovations back by each series' first price, so Exhibit 2 is in price units. This does not change the topology, because each window is standardized in Section 5.3. It does mean that innovations grow when the price level is higher.
Exhibit 2
Kalman innovations for SPY (blue) and GLD (orange), in price units

The swings are small before about 2018 and wider afterwards. SPY has large spikes in early 2020 and in 2025, and GLD in early 2026. Part of this widening is the higher price level seen in Exhibit 1.
5. Persistent homology on the innovation cloud
5.1 The point cloud and the Vietoris–Rips filtration
Take a window of consecutive days. Each day gives one point in the plane: the SPY innovation on one axis and the GLD innovation on the other. Call the set of these points , after each coordinate has been standardized.
For a scale , the Vietoris–Rips complex is
In words: a group of points counts as a simplex (a point, an edge, a filled triangle, and so on) when every pair of points in the group is within distance . As grows, simplices are only added, never removed. This nested growing sequence is called a filtration.
5.2 Persistence diagrams and lifetimes
Persistent homology follows the connected pieces and holes of this growing complex. Each feature is born at some scale and dies at a later scale . Collecting all pairs gives the persistence diagram, and is the lifetime of feature . The study uses two dimensions.
- Dimension 0, connected components. At scale zero, every point is its own component. As grows, points merge, and each merge is the death of one component. Exactly one component never dies, and it is left out when computing finite statistics. A long lifetime means a group of points stays apart from the rest over a wide range of scales, a sign of real clustering. A lifetime near zero means a point joined its neighbours at once.
- Dimension 1, loops. A loop is a closed ring of edges that does not yet enclose a filled region. It is born when it closes and dies when it is filled in. A long-lived loop suggests that the cloud has a ring-like arrangement. The report says this could reflect a lead-lag or mean-reverting relationship between the two series.
For each diagram, the lifetime statistics are
For each window, the study computes three numbers: the maximum lifetime in dimension 0 (), the number of finite features in dimension 0 (), and the maximum lifetime in dimension 1 (). They are computed on the standardized point cloud of that window, up to dimension 1.
Why not a single distance cutoff? A clustering at one fixed distance reports connections at that one scale only. A persistence diagram records every scale at once, and a lifetime shows how much of the range of scales a feature survives. The report adds that persistence diagrams are stable: a small change in the point cloud causes only a small change in the diagram. This is the theoretical reason a lifetime can be treated as a noise-resistant description of shape.
What the number of components really is. Each merge ends one component, and exactly one component survives. So with points, there are always finite features in dimension 0. This is a general fact about the construction, not a result of this study. With 252 points per window, is 251 in every window of this run. A number that never changes cannot signal a regime change. This matters for the flagging rule in Section 6.
As a first look, the notebook also computed the diagrams for the whole sample at once: one cloud of all 4,136 days, not a single window. It has 4,136 features in dimension 0 (one of them never dies) and 1,109 features in dimension 1.
Exhibit 3
Persistence diagrams of the full-sample innovation cloud (4,136 points): connected components (left) and loops (right)

In the left panel, all components are born at zero, and a few die much later than the rest. The dashed line at the top marks the one component that never dies. In the right panel, most loops sit close to the diagonal, which means they are short-lived, and a few lie farther out. The legend of the right panel reads H0 because of a labelling quirk in the plot. Its points are loops. This full-sample picture is for illustration. The detector itself works on windows.
5.3 The sliding window
For an innovation series of length days, the window length and step are
so that consecutive windows overlap by about 80% of their length. The number of windows is
Window covers the days from up to, but not including, . With , this gives (about one trading year), a step of 50, and windows.
Inside every window, each coordinate is standardized to mean 0 and variance 1 before the diagrams are computed. This puts all windows on one scale, so lifetimes from calm and from volatile periods can be compared.
6. The regime flagging rule
Let be any one of the three features, and let be its value in window . For a lookback and a multiplier , define the average and the standard deviation of over the windows just before window :
The feature-level flag is
A window is flagged if any of the three features triggers:
The study uses and . The reported date of a flagged window is its start date.
Four consequences follow.
- Same shape as the baseline. This rule has the same form as the baseline in Section 2. Both compare a current value with its own recent average plus a multiple of its recent standard deviation. What differs is the input: a topological feature of the joint cloud, instead of one asset's volatility. So it inherits the usual weaknesses of such rules. It depends on and , and it can fire from ordinary variability when nothing unusual is happening.
- The first windows cannot be flagged. The average and standard deviation use only earlier windows, so none of the first 5 windows can ever be flagged. That leaves 73 windows that can be.
- The component count cannot fire. In this run is 251 in every window (Section 5.2), so its trailing standard deviation is 0, and the condition is never met. Only and can trigger a flag.
- Runs of flags are more convincing than single flags. Windows overlap heavily, so a real change in the innovation process should flag several consecutive windows. The report says a run of flags, rather than one flag on its own, is the more convincing signature of a real regime shift.
7. Results
7.1 Flagged windows
The notebook computed the three features for all 78 windows and flagged 18 of them. Because the first 5 windows cannot be flagged, that is 18 of the 73 windows that could be. Each date below is the first day of a flagged 252-day window.
| No. | Window start date | Inside a reference stress period |
|---|---|---|
| 1 | 2011-10-14 | No |
| 2 | 2011-12-27 | No |
| 3 | 2012-05-21 | No |
| 4 | 2014-03-07 | No |
| 5 | 2014-05-19 | No |
| 6 | 2014-07-30 | No |
| 7 | 2014-10-09 | No |
| 8 | 2014-12-19 | No |
| 9 | 2016-03-02 | No |
| 10 | 2017-02-28 | No |
| 11 | 2019-05-07 | No |
| 12 | 2019-09-27 | No |
| 13 | 2020-07-15 | No |
| 14 | 2022-07-11 | Yes (2022 period) |
| 15 | 2022-09-20 | Yes (2022 period) |
| 16 | 2023-11-29 | No |
| 17 | 2024-04-24 | No |
| 18 | 2025-04-24 | No |
By year, the flags start in 2011 (2), 2012 (1), 2014 (5), 2016 (1), 2017 (1), 2019 (2), 2020 (1), 2022 (2), 2023 (1), 2024 (1) and 2025 (1).
Exhibit 4
Maximum dimension-0 lifetime in each rolling window. Red crosses mark the 18 flagged windows

7.2 Reading the flags
The plot shows the maximum dimension-0 lifetime, which ranges from about 1 to about 5. The highest value, about 5, is in the window that starts on 2012-05-21, and it is flagged.
Some points are worth noting.
- Runs. The notebook steps 50 days at a time, about ten weeks. By the spacing of the dates, three runs of flags fall on consecutive windows: two in late 2011, five in 2014, and two in 2022. This is derived from the dates, not stated in the notebook. By the report's own criterion, these runs are more convincing than the nine isolated flags. Five flags in a row in 2014 is the longest run, and 2014 is in neither reference period.
- Which feature fired. Several crosses in Exhibit 4 sit at dimension-0 values that are below the level of the windows just before them, for example in March, May and July 2014, and at both 2022 flags. The dimension-0 rule cannot fire there, because it needs a value above its recent average, and the component count never fires. So these flags most likely came from the loop feature. This is an inference from the rule and the plot. The notebook prints only the overall flag dates and does not record which feature triggered each one, and this report does not plot the loop feature.
- The date is the start of the window. Each window covers about one year of data that begins on the flag date. A flag dated in July 2022 describes data from July 2022 to about a year later.
8. Validation against known stress periods
The check uses the dates in Section 7.1 and two known periods of market stress:
| Period | Dates | Flagged windows that start inside |
|---|---|---|
| COVID crash | 2020-02-15 to 2020-04-15 | 0 |
| 2022 inflation sell-off | 2022-01-01 to 2022-10-31 | 2 (2022-07-11 and 2022-09-20) |
| Outside both periods | All other dates | 16 |
The earliest flagged start in the 2022 period is 2022-07-11. The count outside both periods, 16, is derived from the list: 18 flags minus the 0 and the 2 inside the periods.
What this check does and does not show. The report says plainly what this is. It checks whether the detector fires in two known, real episodes. It has no negative examples and no labelled ground truth for what a regime change looks like on a given day. So it is not a precision or recall evaluation. Finding at least one flag in a period is consistent with the detector working, but it says nothing about how often the detector fires under ordinary conditions. A flag outside the periods is also ambiguous. It could be a false alarm, or a real, unlabelled change that the two periods do not cover.
The two periods give different answers. The 2022 period has two flagged starts. The COVID period has none. Two flagged windows, which start on 2019-05-07 and 2019-09-27, are each about a year long, so both include the whole crash period. The next flag starts on 2020-07-15, after it. So by this start-date count, the detector did not fire on the COVID crash. The report names detection lag as a limitation. A break has to last for a meaningful part of a window before the features move enough to cross the threshold.
The other 16 flags. The report gives two examples of real events that could explain flags outside the two periods: the 2013 taper tantrum and the 2018 volatility spike. No flagged window starts in 2013 or in 2018 in this run. The study does not link any of the 16 flags to a specific event.
A more rigorous test would need either simulated data with a known switching time, or a widely agreed list of real regime-change dates.
9. Robustness across asset pairs
To check whether the result is specific to SPY and GLD, the report packages the whole procedure of Sections 4 to 6 as one function. It takes two price series and returns a flag for every window. The function is applied again, with exactly the same parameters and no retuning, to QQQ and TLT. QQQ is a technology-heavy equity fund, and TLT is a long-duration treasury fund. The report notes that the relationship between these two is known to have broken down in 2022.
The report states what it would count as evidence. If the flags for this second pair again cluster around 2022, instead of spreading evenly over the sample, that would be evidence against the idea that the SPY and GLD result was a coincidence. The report also says that with only two pairs, this is a useful but limited check and not a controlled experiment.
The study materials give no flag dates and no flag counts for QQQ and TLT. So this report cannot say whether the flags cluster around 2022 for this pair, and no robustness result is reported here. For comparison, the SPY and GLD flags in Section 7.1 are spread from 2011 to 2025, and only 2 of the 18 start in 2022.
10. Sensitivity to the Kalman parameters
The Kalman model has three free parameters, . They control how closely the estimated trend follows the observed price. A larger relative to lets the level track the price more closely. This gives a looser trend and smaller innovations. A smaller relative to gives a smoother, more inertial trend and larger innovations.
The study varies them over a small grid and counts the flagged windows, , with every other setting fixed.
| Label | |||
|---|---|---|---|
| Tighter trend | |||
| Baseline | |||
| Looser trend |
The grid goes from half to double the baseline for and , which is a factor of four from the tightest to the loosest setting, with held fixed. The report states that the total count of flagged windows stays roughly stable across this grid. It does not give the three counts, so no counts are shown here.
The count is a coarse summary. Two settings could give the same total while flagging entirely different windows. The report uses it only as a rough stability check and does not claim that the flagged dates stay the same. A stronger test would compare the flags themselves, for example by the overlap between sets of flagged dates, or compare the persistence diagrams directly with the bottleneck or Wasserstein distance.
11. Computational cost
Kalman filtering. Each step uses only a small, fixed number of two-by-two matrix operations. Filtering a series of length costs an amount of work in proportion to for each asset. This is small next to the topological stage.
Persistent homology. For a window of points, the work includes forming all pairwise distances, which grows in proportion to . It also includes considering simplices up to dimension 2, because finding loops requires knowing which triangles would fill them. In the worst case their number grows in proportion to , although the software avoids building most of this structure in practice. With for the time to process one window, the total time for the rolling analysis is about
The report says the notebook measures this with a timer, but it gives no measured run time. So none is shown here. It makes two points about scaling.
- As the window length grows, the cost per window grows faster than linearly. So the choice of window length is a trade-off in computing cost as well as a statistical trade-off between detection lag and noise.
- As the number of assets grows, the point cloud lives in a higher-dimensional space but, for a fixed window, has no more points. It becomes sparse, and its statistical meaning weakens, usually before the computing cost becomes a problem. Beyond about five assets, some form of dimension reduction, such as principal component analysis, or a different multiscale summary, such as persistence landscapes, becomes the natural way forward.
12. Conclusion
The pipeline combines four ideas. The Kalman filter isolates the part of each price series that cannot be predicted one step ahead. Persistent homology, a multiscale shape description with a stability guarantee, is applied to the joint cloud of those innovations. Each window's diagram is reduced to three numbers. A trailing threshold rule is then applied to them, with the same structure as the volatility baseline.
What the study shows and does not show:
| Question | What the study shows |
|---|---|
| Does the detector flag windows? | Yes: 18 of 78 windows, on 4,136 trading days of SPY and GLD |
| Does it flag the 2022 stress period? | Two flagged windows start between January and October 2022 |
| Does it flag the COVID crash period? | No flagged window starts between 15 February and 15 April 2020 |
| Does it see more than a volatility threshold? | Not shown: no baseline result is reported |
| Does it hold on a second pair (QQQ and TLT)? | Not shown: the check is described, but no flag counts are given |
| Is the flag count stable across Kalman parameters? | The report says the count stays roughly stable across the grid (Section 10), with no counts given |
| Is the false-alarm rate known? | No |
The report describes its own checks as a sanity check against two known episodes, not a formal proof and not a labelled backtest. It describes the pipeline as a carefully checked prototype, not a fully validated detector. To move further, it says the work needs labelled ground truth, maximum likelihood estimation of the Kalman parameters, dimension reduction for more than about five assets, and an explicit analysis of the false-alarm rate under repeated, overlapping tests.
Limitations
- No ground truth. The validation checks two known episodes and has no labelled regime changes. There is no agreed definition of a regime change at the level of a single window to score against. The study cannot give precision or recall.
- No baseline comparison. The volatility rule is defined, but no baseline result is reported. So the study does not show that the topological detector sees anything that a volatility threshold misses.
- One feature carries no information. The count of connected components is 251 in every window by construction, so it can never trigger a flag. Only two of the three features can. The notebook does not record which feature triggered each flag.
- Still a threshold rule. Replacing a volatility threshold with a topological one changes what is measured, not how the decision is made. The rule depends on the lookback of 5 windows and the multiplier of 2. It can fire from ordinary variability. It is unstable when the trailing windows themselves span a regime boundary. It has no explicit control of the false-alarm rate over many overlapping, correlated windows.
- Detection lag and window length. A real break has to last for a meaningful part of the 252-day window before the features cross the threshold. A shorter window reduces the lag but makes each diagram noisier, which raises the chance of false alarms. The window length follows a simple rule tied to the sample size, not a principled choice.
- Parameters are chosen, not fitted. The Kalman parameters are a modelling choice. They are not estimated by maximum likelihood, although the likelihood can be computed exactly from the innovations and their variances. The sensitivity check compares only flag counts, not which windows are flagged.
- Few dimensions. The method works best on low-dimensional clouds, roughly up to five assets. A larger portfolio would need dimension reduction.
- Two pairs at most, and no reported result for the second. The robustness check uses one extra pair, and its outcome is not reported in the study materials. The report also notes a fragility in the study code for this check. The code contains a second, placeholder definition of the filter whose update step always returns an innovation of zero. Depending on how the code is run, the Kalman stage of the check could quietly collapse to a constant zero series, and the homology stage would then work on a degenerate cloud. The report says this does not change the method as defined.
Research by Lanre Ibrahim. Source: TDA + Kalman notebook and the Kalman filters and persistent homology report. Historical tests on past data; not investment advice and not the record of any managed account.