Cointegration (COINTEGRATION)
Category: market_structure
Calculates the cointegration of two assets using the Engle-Granger two-step method, providing an Augmented Dickey-Fuller (ADF) test statistic for the residuals. Lower (more negative) values indicate a stronger mean-reverting relationship between the assets.
Formula
\begin{cases} \beta = \text{Correlation}(A, B) \cdot \frac{\sigma_A}{\sigma_B} \\ \alpha = \text{SMA}(A) - \beta \cdot \text{SMA}(B) \\ \epsilon_t = A_t - (\alpha + \beta B_t) \\ \Delta\epsilon_t = \epsilon_t - \epsilon_{t-1} \\ \gamma = \frac{\text{Cov}(\Delta\epsilon_t, \epsilon_{t-1})}{\text{Var}(\epsilon_{t-1})} \\ \text{ADF Statistic} = \frac{\gamma}{\text{SE}(\gamma)} \end{cases}
Inputs
- Source 1 (default: close)
- Source 2 Ticker (default: SPY)
- Period (default: 20)
See signal primitives, usage in published strategies and more on WOBR StrategyVerse.