Lyapunov Exponent

Calculate the Lyapunov Exponent of each asset’s log returns: the rate, per period, at which nearby paths of the reconstructed dynamics move apart, positive for a chaotic process.

A positive largest exponent points to chaos, a sensitive dependence on the starting point that makes the series unpredictable beyond a few periods even if it were deterministic; a value around 0 or below to a regular process. For noise, such as daily returns, the estimate is not 0 but depends on the embedding, so the exponent is mostly of use to compare assets or periods with each other.

The methods are as follows (\(X_{i}\) the delay embedding of the log returns x):

\[\text{Rosenstein, Collins and De Luca (1993):}\;\; \text{every vector } X_{i} \text{ is paired with its nearest neighbour } X_{j} \text{ (Euclidean) at least min\_separation periods away},\;\; y(k) = \operatorname{Mean}(\ln \left\|X_{(i+k)} - X_{(j+k)}\right\|) \;\text{for}\; k = 0,\; \ldots,\; \text{trajectory\_length} - 1,\;\; \text{and}\;\; \lambda_{1} = \text{slope of} \;y(k) \;\text{on}\; k,\;\; \text{the largest exponent}\] \[\text{Eckmann, Kamphorst, Ruelle and Ciliberto (1986):}\;\; \text{with}\;\; m = \frac{\text{embedding} - 1}{\text{matrix\_dimension} - 1},\;\; \text{a linear map}\; T_{i} \;\text{from}\; X_{i} = \left[x_{i},\; x_{i+m},\; \ldots\right] \;\text{to}\; X_{(i+m)} \;\text{is fitted by least squares on the}\; \text{min\_neighbors} \;\text{nearest neighbours} \;(\text{Chebyshev});\;\; \text{the maps are multiplied along the path with a QR decomposition}\; T_{i} Q_{i-m} = Q_{i} R_{i}\;\;\text{and}\;\; \lambda_{k} = \frac{\operatorname{Mean}(\ln \;\text{abs}(R_{i,\text{kk}}))}{m},\;\; \text{the matrix\_dimension largest exponents}\]

Also known as: largest Lyapunov exponent, LLE, Lyapunov spectrum, chaos exponent.

Example · EURUSD, GCUSD, BTCUSD · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_lyapunov_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_lyapunov_exponent()

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

How quickly did nearby paths of the daily returns of the euro against the dollar, gold, Bitcoin and the S&P 500 drift apart from 2021 to 2025, measured by the Lyapunov exponent?

Which returns:

Parameters

get_lyapunov_exponent accepts the following parameters.

ParameterTypeDescriptionExample
methodstrThe algorithm. Options are: “rosenstein” (Rosenstein, Collins and De Luca, the largest exponent), “eckmann” (Eckmann, Kamphorst, Ruelle and Ciliberto, the spectrum). Defaults to “rosenstein”."rosenstein"
periodstr | NoneThe data frequency. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to None, which uses “daily”."weekly"
embeddingintThe embedding dimension; for “eckmann”, embedding - 1 must be a multiple of matrix_dimension - 1. Defaults to 10.10
delayintThe number of periods between the returns of a vector of the Rosenstein method. Defaults to 1.1
min_separationint | NoneThe smallest number of periods between a vector and its neighbour. Defaults to None, which uses the mean period of the returns (one over the power-weighted mean frequency of the periodogram, rounded up) for “rosenstein” and 0 for “eckmann”.None, which uses the mean period of the returns (one over the power-weighted mean frequency of the periodogram, rounded up) for "rosenstein" and 0 for "eckmann"
trajectory_lengthintThe number of periods the pairs of the Rosenstein method are followed. Defaults to 20.20
matrix_dimensionintThe number of exponents of the Eckmann method. Defaults to 4.4
min_neighborsint | NoneThe number of neighbours of every vector of the Eckmann method. Defaults to None, which uses min(2 * matrix_dimension, matrix_dimension + 4).None, which uses min(2 * matrix_dimension, matrix_dimension + 4)
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 Rosenstein, M.T., Collins, J.J. & De Luca, C.J. (1993). “A practical method for calculating largest Lyapunov exponents from small data sets.” Physica D, 65(1-2), 117-134.
  • Paper Eckmann, J.-P., Kamphorst, S.O., Ruelle, D. & Ciliberto, S. (1986). “Liapunov exponents from time series.” Physical Review A, 34(6), 4971-4979.
  • Library Referenced against nolds’ lyap_r (Rosenstein)
  • Library Referenced against nolds’ lyap_e (Eckmann)
Share