Detrended Fluctuation Analysis

The Detrended Fluctuation Analysis (DFA) of Peng et al. (1994), introduced for the long-range correlations in DNA sequences, estimates the Hurst exponent from how the fluctuations of the cumulative returns around a local trend grow with the window length. Removing the trend in every window keeps slow drifts in the level from passing for long memory.

The formula for the Detrended Fluctuation Analysis starts from the profile of the N log returns x, the cumulative sum of their deviations from the mean, for \(k = 1\), …, N:

\[Y_{k} = \sum_{i=1}^{k} \left(x_{i} - \operatorname{mean}\left(x\right)\right)\]

The profile is cut into windows of n periods, and in every window a polynomial trend \(Y_{n} (k)\) (a straight line by default) is fitted by least squares. The fluctuation F(n) is the root mean square of the profile around those trends, the mean running over the points of all windows:

\[F(n) = \sqrt{\operatorname{mean}\left((Y_{k} - Y_{n}(k))^{2}\right)}\]

The exponent H, the scaling exponent alpha of the paper, is the slope of the logarithm of the fluctuation on that of the window length, with Slope(y, x) the least squares slope of y on x over the window lengths n:

\[H = \text{Slope}\left(\ln\left(F(n)\right), \ln\left(n\right)\right)\]

For returns without memory the fluctuation grows with the square root of \(n (H = 0.5)\); a higher H is a trending and a lower H a mean-reverting price.

The Hurst Exponent (H) measures the long-term memory of a series: whether a move tends to be followed by a move in the same direction or by a reversal. Harold Edwin Hurst found it in the yearly floods of the Nile, whose wet and dry years cluster more than independent years would, and Benoit Mandelbrot carried it over to prices. Each method measures how fast some spread of the price path grows with the horizon: for a random walk it grows with the square root of the horizon, which gives \(H = 0.5\). The Hurst Exponent is interpreted as follows:

  • \(H < 0.5\): the series is mean-reverting (anti-persistent).
  • \(H = 0.5\): the series is a random walk (no memory).
  • \(H > 0.5\): the series is trending (persistent).

For liquid stocks the estimate is usually close to 0.5, and from daily data over short horizons it describes short-term behaviour only. A value slightly away from 0.5 over a few years is usually within the estimation noise rather than evidence of a tradable pattern, so the exponent is mostly of use to compare assets with each other or a rolling estimate over time.

Also known as: DFA, DFA exponent, detrended fluctuation.

In the Finance Toolkit this is get_hurst_exponent with method="detrended_fluctuation", the same function as Hurst Exponent.

Example · EURUSD, GCUSD, BTCUSD · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_hurst_exponent:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["EURUSD", "GCUSD", "BTCUSD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_hurst_exponent(method="detrended_fluctuation")

Which returns:

References

  • Paper Peng, C.-K., Buldyrev, S.V., Havlin, S., Simons, M., Stanley, H.E. & Goldberger, A.L. (1994). “Mosaic organization of DNA nucleotides.” Physical Review E, 49(2), 1685-1689.
  • Library Referenced against nolds’ dfa (Detrended Fluctuation Analysis)
  • Library Shares similar logic as antropy’s detrended_fluctuation (Detrended Fluctuation Analysis)
Share