Basic Prerequisites: 03 · Target Labeling and 05 · Failure Modes & Practice.


1. Intuition & Practical Objective

Two problems remain after the triple barrier and meta-labeling are in place, and this page supplies the standard tooling for both.

Problem 1 - stationarity vs memory. Prices are non-stationary; returns are stationary but memoryless. Neither extreme is right. Fractional differentiation (López de Prado Ch 5) finds the minimum differencing order that passes a unit-root test while preserving the maximum correlation with the original (memory-bearing) levels - a stationarity–memory frontier you control with one number.

Problem 2 - the draws are not IID. Overlapping labels make consecutive observations share returns, so the empirical distribution is wrong and any IID-based bootstrap or CV is invalid. Sample weights derived from label uniqueness (Ch 4) re-weight the observations so the effective sample behaves like an IID one; the sequential bootstrap goes further and samples so that the sequence of draws is closer to IID. Finally, because a genuinely new regime makes old data misleading, structural breaks (Ch 17) mark the boundaries of what is still relevant.

The one-sentence essence. “Difference just enough to be stationary (, not ), and weight each observation by how unique its information is () - because in finance the two biggest lies are that levels are stationary and that draws are IID.”


2. Mathematical Ground Truth & Derivations

2.1 Fractional differentiation and the minimum order

The backward-shift operator satisfies with the binomial series

so the differentiated series is a dot product with weights generated iteratively (LdP eq. 5.3–5.5):

For , - a pure first difference with no memory. For the decay very slowly and memory persists. Expanding-window implementation computes each with all available weights, which injects a negative drift and varies the “memory depth” across the sample. The fixed-width window (FFD) drops weights once :

so every estimate uses the same weights and the drift vanishes. The minimum order is then

quantifies exactly how much memory must be sacrificed for stationarity; falls as rises, and you want the largest correlation among the .

2.2 Sample weights from uniqueness

With concurrency and the indicator matrix ( if label spans bar ), the average uniqueness is (LdP Ch 4)

and the natural sample weight is (optionally a time-decay factor and a return-attribution factor). The sequential bootstrap: draw observations one at a time, and at each step down-weight the observations that overlap those already drawn, so the resulting in-bag set approximates IID sampling. Return attribution splits each label’s return across the bars it spans (by uniqueness), so that overlapping bars are counted exactly once.

Sample weights enter the training objective as a weighted loss, e.g. weighted cross-entropy

which is how the “non-IID draws” correction actually reaches the learner.

2.3 Structural breaks

Regime changes (LdP Ch 17) invalidate the stationarity assumption over long samples. Detecting them and re-fitting (or re-weighting) after each break prevents the model from averaging over incompatible worlds - the same disease as under-differencing, at the level of the whole sample.


3. Computational Implementation - the search and the memory trade-off

The snippet implements the fractional-weights recursion, the fixed-width window, and a Dickey–Fuller statistic (normal equations), then scans to find and reports the memory retained ( with the original level) at each . Standard library only.

Read the table as the stationarity–memory frontier. At the level fails the unit-root test (); at it is emphatically stationary () but has essentially no memory (). The crossover is at –: is barely stationary (, just past the threshold) and retains of the level, while is comfortably stationary () and still keeps . The whole point: use , not . The learner should see the series (or the one, after confirming stability across a rolling ADF) - a stationary feature that still remembers two-thirds of the price’s history, rather than returns that remember none of it.


4. Failure Modes & First-Principles Breakdowns

  1. Choosing by eye or by convention. must be established by the unit-root test on your series, -threshold and all; a fixed copied from a paper is not a result.
  2. Expanding-window drift. The expanding-window fracdiff injects a negative drift (added weights at the start). Use the fixed-width window so every estimate uses the same weights.
  3. Stationarity tested on the wrong series. Testing the differenced series against the original’s critical values, or ignoring the weight-loss threshold’s effect on the test.
  4. Weights ignored by the learner. Computing uniqueness and then training an unweighted model discards the entire Ch-4 correction; the weighted loss must actually be used.
  5. Sequential bootstrap done wrong. Re-drawing observations whose spans are already in-bag re-introduces the overlap the method exists to remove.
  6. Averaging across structural breaks. Fitting one model over a sample that contains a regime change averages incompatible distributions. Detect breaks and re-fit or re-weight (LdP Ch 17).
  7. Looking at the label while differencing. is a property of the feature series and must be chosen without reference to the label, or it becomes another overfitting channel.

5. References

  • López de Prado, M.: Advances in Financial Machine Learning (2018)
  • Hosking, J.R.M. (1981): Fractional differencing, Biometrika 68(1)
  • Tsay, Ruey S.: Analysis of Financial Time Series
  • Hastie, Tibshirani & Friedman: The Elements of Statistical Learning

6. Connected Graph Bridges