Correlation Dimension

Calculate the Correlation Dimension of each asset’s log returns by the Grassberger-Procaccia algorithm: the dimension of the set that stretches of consecutive returns fill, low for a deterministic process.

A deterministic, chaotic process fills a set of a low dimension however many returns a stretch holds; for noise the dimension grows with the embedding dimension (close to it for independent returns). Daily returns behave mostly like noise, so a value well below the embedding dimension is the exception, and comparing several embedding dimensions shows whether the dimension levels off.

The formula is as follows:

\[X_{i} = \left[x_{i},\; x_{i+\tau},\; \ldots,\; x_{}(i + (m - 1) \cdot \tau)\right],\;\; \text{the delay embedding of the log returns}\] \[C(r) = \frac{2}{M \cdot (M - 1)} \cdot \operatorname{Sum}(1\left[\left\|X_{i} - X_{j}\right\| < r\right],\; i < j),\;\; \frac{\text{the share of the}\; M \cdot (M - 1)}{2 \;\text{pairs of vectors closer than}\; r}\] \[D_{2} = \text{slope of}\; \ln C(r) \;\text{on}\; \ln r\]

with ||.|| the Euclidean norm and, by default, the radii (3% apart) at which C(r) lies between 0.0001 and 0.01.

Also known as: D2, Grassberger-Procaccia dimension, correlation integral.

Example · EURUSD, GCUSD, BTCUSD · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_correlation_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_correlation_dimension(embedding=4)

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

What was the correlation dimension of the daily returns of the euro against the dollar, gold, Bitcoin and the S&P 500 from 2021 to 2025, with an embedding dimension of 4?

Which returns:

Parameters

get_correlation_dimension accepts the following parameters.

ParameterTypeDescriptionExample
periodstr | NoneThe data frequency. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to None, which uses “daily”."weekly"
embeddingintThe embedding dimension m. Defaults to 10.10
delayintThe number of periods between the returns of a vector. Defaults to 1.1
radiilist[float] | NoneThe radii as multiples of the standard deviation (with n - 1 in the denominator) of the returns. Defaults to None, which uses the radii at which C(r) lies between 0.0001 and 0.01.
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 Grassberger, P. & Procaccia, I. (1983). “Characterization of strange attractors.” Physical Review Letters, 50(5), 346-349.
  • Library Shares similar logic as nolds’ corr_dim
Share