Minimum Fractional Difference

Calculate the minimum order of fractional differentiation d that makes the log prices stationary, per asset: the smallest d at which the fixed-width fractional difference passes the Augmented Dickey-Fuller test, the stationary series that keeps the most memory of the prices (López de Prado, 2018, section 5.6).

The formula is as follows, with \(X_{t}\) the log of the column (Adj Close by default):

\[\text{For}\; d = 0,\; 0.1,\; \ldots,\; 1 \;(\text{step}) \;\text{:} \tilde{X} = \operatorname{FFD}(X,\; d) \;\text{of} \;\text{get\_fractional\_difference} \;\text{with the weight threshold} \;(0.01 \;\text{by default}) \;\text{and the ADF test on}\; \tilde{X} \;\text{with} \;\text{get\_unit\_root\_test} \;(\text{constant},\; \text{lags by AIC up to} \;\text{max\_lag},\; 1 \;\text{by default}),\;\; \text{as in López de Prado's Snippet 5.4}\] \[d^{*} = \text{the smallest}\; d \;\text{whose ADF p-value is below}\; 1 - \text{confidence} \;(0.05 \;\text{by default}),\;\; \frac{\text{refined in steps of step}}{10 \;\text{between the last}\; d \;\text{that fails and the first that passes}}\] \[\text{Correlation} = \text{the correlation of}\; \tilde{X} \;\text{with}\; X \;\text{over the dates of}\; \tilde{X},\;\; \text{the memory kept}\]

Also known as: minimum d, optimal fractional differentiation, minimum FFD, memory-preserving stationarity.

Example · AAPL, MSFT · 2016 to 2025

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

from financetoolkit import Toolkit

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

toolkit.econometrics.get_minimum_fractional_difference()

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

What is the smallest fractional difference that makes the share prices of Apple and Microsoft stationary while keeping most of their memory, from 2016 to 2025?

Which returns:

Using Your Own Data

get_minimum_fractional_difference 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_minimum_fractional_difference()

Parameters

get_minimum_fractional_difference accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column to test. Defaults to “Adj Close”."Return"
confidencefloatThe confidence of the ADF test: the p-value has to be below 1 - confidence. Defaults to 0.95.0.95
stepfloatThe step of the grid of d from 0 to 1. Defaults to 0.1.0.1
thresholdfloatThe smallest absolute weight of the fixed-width window. At 1e-5 the window of \(d = 0.1\) spans about 4,000 observations and at 1e-4 about 500, so on a few years of data a small d leaves too few values to test. Defaults to 0.01.0.01
max_lagint | NoneThe largest lag of the ADF lag search. Defaults to 1, as López de Prado (2018) uses. None searches up to min(ceil(12·(n / 100)^(1/4)), (n - 5) // 3) lags by AIC, which on daily data picks many lags, weakens the test and pushes the minimum d towards 1.
log_pricesboolWhether to take the natural logarithm of the series first. Pass False for a series that can be zero or negative, such as a rate. Defaults to True.True
gridboolWhether to return the ADF test, the correlation and the window width for every d tried instead of the minimum d per asset. Defaults to False.False
include_benchmarkboolWhether to include “Benchmark” among the assets. Defaults to False.True
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 López de Prado, M. (2018). “Advances in Financial Machine Learning.” Wiley, section 5.6 (Snippet 5.4).
  • Paper Dickey, D.A. and Fuller, W.A. (1979). “Distribution of the Estimators for Autoregressive Time Series with a Unit Root.” Journal of the American Statistical Association, 74(366a), 427-431.
  • Library Referenced against RiskLabAI’s find_optimal_ffd_simple
Share