Fractal Dimension

Calculate the Fractal Dimension of each asset’s log price path: how rough the path is, between 1 for a straight line and 2 for a path that fills the plane.

A random walk has a Higuchi dimension of 1.5, which is 2 - H for a self-affine path with Hurst exponent H: a trending path has a lower and a mean-reverting path a higher dimension. The Katz and Petrosian dimensions are quick measures of the same roughness on their own scales: Katz from how far the path gets for the distance it travels and Petrosian from how often it turns. Price paths are close to random walks, so the dimensions are mostly of use to compare assets or periods (with rolling).

The methods are as follows (on the log prices x of N periods):

\[\text{Higuchi (1988):}\;\; L_{m}(k) = \frac{\frac{\operatorname{Sum}(\operatorname{abs}(x_{m+i*k} - x_{}(m + (i - 1) \cdot k))) \cdot (N - 1)}{\left\lfloor \frac{N - m}{k} \right\rfloor \cdot k}}{k},\;\; L(k) = \operatorname{Mean}(L_{m}(k)) \;\text{over}\; m = 1,\; \ldots,\; k,\;\; \text{and}\;\; \text{FD} = - \text{slope of}\; \ln L(k) \;\text{on}\; \ln k \;\text{over}\; k = 1,\; \ldots,\; \text{kmax}\] \[\text{Katz (1988):}\;\; \text{FD} = \frac{\log_{10}(n)}{\log_{10}(n) + \log_{10}\left(\frac{d}{L}\right)},\;\; \text{with}\;\; L = \operatorname{Sum}(\operatorname{abs}(x_{i+1} - x_{i})) \;\text{the length of the path},\;\; d = \max(\operatorname{abs}(x_{i} - x_{1})) \;\text{its largest distance from the start}\;\;\text{and}\;\; n = N - 1 \;\text{the number of steps}\] \[\text{Petrosian (1995):}\;\; \text{FD} = \frac{\log_{10}(N)}{\log_{10}(N) + \log_{10}\left(\frac{N}{N + 0.4 \cdot N_{\delta}}\right)},\;\; \text{with } N_{\delta} \text{ the number of sign changes of the returns (a return of 0 interrupts one)}\]

Also known as: HFD, KFD, PFD, Higuchi fractal dimension, fractal roughness.

Example · EURUSD, GCUSD, BTCUSD · 2021 to 2025

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

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_fractal_dimension()

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

How rough were the price paths of the euro against the dollar, gold, Bitcoin and the S&P 500 from 2021 to 2025, measured by their Higuchi fractal dimension?

Which returns:

Parameters

get_fractal_dimension accepts the following parameters.

ParameterTypeDescriptionExample
methodstrThe fractal dimension. Options are: “higuchi” (Higuchi), “katz” (Katz), “petrosian” (Petrosian). Defaults to “higuchi”."higuchi"
periodstr | NoneThe data frequency. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to None, which uses “daily”."weekly"
rollingint | NoneThe number of periods of a rolling window, at least kmax + 2 for “higuchi” (12 by default) and 3 for the others. Defaults to None, which calculates one value over the full history of every asset.4
kmaxintThe largest step k of the Higuchi dimension. Defaults to 10.10
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Higuchi, T. (1988). “Approach to an irregular time series on the basis of the fractal theory.” Physica D, 31(2), 277-283.
  • Paper Katz, M.J. (1988). “Fractals and the analysis of waveforms.” Computers in Biology and Medicine, 18(3), 145-156.
  • Paper Petrosian, A. (1995). “Kolmogorov complexity of finite sequences and recognition of different preictal EEG patterns.” Proceedings of the Eighth IEEE Symposium on Computer-Based Medical Systems, 212-217.
  • Library Referenced against antropy’s higuchi_fd
  • Library Referenced against antropy’s katz_fd
  • Library Referenced against antropy’s petrosian_fd
Share