Approximate Entropy

The Approximate Entropy (ApEn) of Pincus (1991) is the average logarithmic likelihood that stretches of m values that are alike stay alike at the next value. It was the first regularity statistic built for the short and noisy series of clinical data, where the entropies of dynamical systems theory need far more observations.

The formula for the Approximate Entropy first sets the tolerance r, a multiple c of the sample standard deviation of the series x (c is 0.2 by default):

\[r = c \cdot \operatorname{std}\left(x\right)\]

Two templates, the stretches of m values (2 by default) from positions i and j, are alike when their largest distance over the positions \(k = 0\) to m - 1 is at most r:

\[D_{m}(i, j) = \max\left(\left\lvert x(i + k) - x(j + k)\right\rvert\right)\]

\(C_{i} (m)\) is the share of the templates of m values within r of template i, itself included, and Phi(m) the average of their logarithms:

\[\Phi(m) = \operatorname{mean}\left(\ln\left(C_{i}(m)\right)\right)\]

The entropy is the drop in Phi from templates of m values to templates of m + 1 values:

\[\text{ApEn} = \Phi(m) - \Phi(m + 1)\]

A low Approximate Entropy means a regular series, a high value an irregular one. Counting every template as a match of itself keeps the logarithms finite but biases the value towards regularity in short series and makes it depend on the length of the series; the Sample Entropy removes that bias.

An entropy measures how irregular and unpredictable a series is. It is low for a series that repeats itself, trends or is driven by a few cycles, and high for a series that looks like noise. The entropies come from information theory (Shannon, 1948) and from the study of physiological signals such as heart rate and EEG, where they tell regular rhythms from irregular ones; López de Prado (2018) applies them to financial series as features of how much structure the returns hold. They differ in what they count: matching stretches of values, the order of values, the spread of the power spectrum, or the symbols of encoded returns. On daily returns, which are close to noise, most entropies sit near their maximum, so they are of most use to compare assets or periods with each other, such as a rolling value over time, rather than as an absolute level.

Also known as: ApEn.

In the Finance Toolkit this is get_entropy with method="approximate", the same function as Entropy.

Example · AAPL, MSFT, NVDA · 2021 to 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["AAPL", "MSFT", "NVDA"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_entropy(method="approximate", rolling=252)

Which returns:

Using Your Own Data

get_entropy runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_entropy()

References

  • Paper Pincus, S.M. (1991). “Approximate entropy as a measure of system complexity.” Proceedings of the National Academy of Sciences, 88(6), 2297-2301.
  • Library Referenced against antropy’s app_entropy (Approximate Entropy)
Share