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):
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:
| Item | AAPL | MSFT |
|---|---|---|
| Minimum d | 0.5300 | 0.5600 |
| ADF Statistic | -2.9108 | -2.9734 |
| P-Value | 0.0441 | 0.0375 |
| Critical Value 5% | -2.8627 | -2.8627 |
| Correlation | 0.9917 | 0.9919 |
| Window Width | 10.0000 | 9.0000 |
| Observations | 2,503.0000 | 2,504.0000 |
7 rows
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.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to test. Defaults to “Adj Close”. | "Return" |
confidence | float | The confidence of the ADF test: the p-value has to be below 1 - confidence. Defaults to 0.95. | 0.95 |
step | float | The step of the grid of d from 0 to 1. Defaults to 0.1. | 0.1 |
threshold | float | The 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_lag | int | None | The 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_prices | bool | Whether 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 |
grid | bool | Whether 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_benchmark | bool | Whether to include “Benchmark” among the assets. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
show_columns | str | list[str] | None | The 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