bds#
- cultivars.diagnostics.nonlinearity.bds(endog, *, dimension=3, epsilon=None)[source]#
The BDS test of independence, usually on residuals.
The correlation integral of the \(m\)-histories at radius \(\varepsilon\),
\[C_m(\varepsilon) = \binom{T_m}{2}^{-1} \sum_{s < t} \mathbb{1}\bigl\{\|y^m_s - y^m_t\|_\infty < \varepsilon\bigr\},\]is compared with the \(m\)-th power of the one-point integral, which is what independence implies; the standardized gap is asymptotically standard normal, and the test is run at every dimension from 2 to
dimensionwith the same radius. The radius defaults to1.5standard deviations of the series, the choice with the best size in the Brock et al. tables, and the reference is trustworthy from about 500 observations. On GARCH residuals with 500 observations the test rejects about 90% of the time, which is its most common use: what the ARCH test says with a form, BDS says without one.- Parameters:
endog (
ArrayLike) – The series, typically standardized residuals, at least10 * dimension + 50observations.dimension (
int) – Largest embedding dimension \(m\), at least 2;2and every dimension up to it are reported.epsilon (
float|None) – Radius in the units of the series;Nonetakes1.5standard deviations.
- Return type:
- Returns:
The
BDSTestatdimension, lower dimensions ascompanions.- Raises:
SpecificationError – If the dimension is below 2, the radius is not positive, or the series is too short.
NumericalError – If a value is not finite, or the radius leaves no pairs close or every pair close.
Note
Applied to residuals from an estimated model the statistic’s limit is unchanged for linear models, by Brock’s theorem, but not for GARCH-standardized residuals, where it is mildly conservative; the 90% power figure is on the raw GARCH series. The cost is \(O(T^2)\) in memory and time through the pairwise distances.
See also
BDSTest– the record, with the reading rule for residuals in its summary.tsay(),terasvirta(),hansen_threshold()– the tests that name an alternative.
References
Brock, W. A., Dechert, W. D., Scheinkman, J. A., & LeBaron, B. (1996). A test for independence based on the correlation dimension. Econometric Reviews, 15(3), 197-235.
Brock, W. A., Hsieh, D. A., & LeBaron, B. (1991). Nonlinear Dynamics, Chaos, and Instability: Statistical Theory and Economic Evidence. MIT Press.
Example
Gaussian noise keeps independence; a radius far below the series’ scale leaves no close pairs and is refused:
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> y = rng.standard_normal(600) >>> bool(bds(y).pvalue > 0.01) True >>> bds(y, epsilon=1e-9) Traceback (most recent call last): ... cultivars.exceptions.NumericalError: a radius of 1e-09 leaves the correlation integral ...