BDS Test

Calculate the BDS test of every asset’s returns: whether they are independent and identically distributed, against any kind of dependence, linear or nonlinear.

The test counts how often two stretches of dimension consecutive returns are close to each other and compares that with what independent returns would give. Returns with no autocorrelation can still fail it through volatility clustering, which makes calm and turbulent stretches resemble each other. Applied to the standardized residuals of a GARCH model, a pass means the model captured the dependence.

The formula is as follows:

\[I_{s,t} = 1 \quad \text{if } \left\lvert r_{s} - r_{t}\right\rvert < \epsilon\] \[I_{s,t} = 0 \quad \text{if } \left\lvert r_{s} - r_{t}\right\rvert \geq \epsilon\] \[\epsilon = 1.5 \cdot \operatorname{std}\left(r\right)\] \[n_{m} = n - m + 1\] \[C_{m} = \frac{2}{n_{m} \cdot (n_{m} - 1)} \cdot \sum \left(\prod_{j=0}^{m - 1} I_{s+j,t+j}\right)\] \[K = \frac{\sum_{t=1}^{n} \left(c_{t}^{2} - c_{t}\right)}{n \cdot (n - 1) \cdot (n - 2)}\] \[\text{where}\;\; c_{t} = \sum I_{s,t}\] \[\sigma_{m}^{2} = 4 \cdot \left(K^{m} + 2 \cdot \sum_{j=1}^{m - 1} K^{m - j} \cdot C^{2 \cdot j} + (m - 1)^{2} \cdot C^{2 \cdot m} - m^{2} \cdot K \cdot C^{2 \cdot m - 2}\right)\] \[W = \frac{\sqrt{n_{m}} \cdot \left(C_{m} - C_{1,m}^{m}\right)}{\sigma_{m}}\] \[\text{P Value} = 2 \cdot \left(1 - \Phi\left(\left\lvert W\right\rvert\right)\right)\]

with r the returns of period, epsilon 1.5 times their standard deviation (ddof = 1), the middle of the 0.5 to 2 BDS recommend, and m = dimension (2 by default). The sum of \(C_{m}\) runs over all pairs \(s < t\), the sum of \(c_{t}\) over every s other than t. \(C_{1 , m}\) is \(C_{m}\) for single returns (\(m = 1\)) over the last \(n_{m}\) returns and C is \(C_{1}\) over all n returns. W is standard normal under independence, with Phi its distribution function.

Also known as: Brock-Dechert-Scheinkman test, BDS independence test, nonlinearity test.

Example · ^GSPC, BTCUSD, TLT · 2021 to 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["^GSPC", "BTCUSD", "TLT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_bds_test(dimension=3)

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

Were the daily returns of the S&P 500, Bitcoin and the iShares 20+ Year Treasury Bond ETF independent from 2021 to 2025, by the BDS test with an embedding dimension of 3?

Which returns:

Using Your Own Data

get_bds_test 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_bds_test()

Parameters

get_bds_test accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
within_periodboolWhether to calculate the test within the specified period or for the entire period. Thus whether to look at the test within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to False. Note that this requires intraday data when period = ‘daily’, since a single day only nests observations when intraday data was fetched.True
dimensionintThe embedding dimension m, the length of the stretches compared, at least 2. Defaults to 2.2
include_benchmarkboolWhether to include “Benchmark” among the assets tested. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.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 Brock, W.A., Dechert, W.D., Scheinkman, J.A. and LeBaron, B. (1996). “A Test for Independence Based on the Correlation Dimension.” Econometric Reviews, 15(3), 197-235.
  • Paper Kanzler, L. (1999). “Very Fast and Correctly Sized Estimation of the BDS Statistic.” Working paper, University of Oxford.
  • Library Referenced against statsmodels’ bds
Share