co-eco
Quasi-likelihood ratio tests for cointegration, cobreaking, and cotrending
A Python implementation of the econometric tests proposed by Carrion-i-Silvestre and Kim (2019) for testing cointegration, cobreaking, and cotrending in time series data with structural breaks.
Overview
This package provides three types of tests:
-
Robust Cointegration Test (Q_r): Tests the null hypothesis of cointegration regardless of whether structural breaks are present (robust to the presence or absence of breaks).
-
Joint CI/CB Test (Q_cb): Tests the joint null hypothesis of cointegration AND cobreaking (breaks cancel out).
-
Joint CI/CT Test (Q_ct): Tests the joint null hypothesis of cointegration AND cotrending (both breaks and linear trends cancel out). Only applicable for Model II.
Additionally, Dmax tests are provided for determining the number of breaks when testing cobreaking or cotrending.
Installation
pip install co-eco
Or install from source:
git clone https://github.com/merwanroudane/coeco.git
cd coeco
pip install -e .
Quick Start
import numpy as np
from co_eco import CKTest
# Generate example data
np.random.seed(42)
T = 200
x = np.cumsum(np.random.randn(T, 1), axis=0) # I(1) regressor
y = 0.5 * x.flatten() + np.cumsum(np.random.randn(T)) # Cointegrated
# Run tests
test = CKTest(y, x, model=2, klags=2, kleads=2)
results = test.run(num_breaks=1)
# Display results
print(results)
Detailed Usage
Model Specifications
- Model I: Mean shifts only (no linear trend)
- Model II: Linear trend with intercept shifts
Known Break Dates
from co_eco import ck_test_known_breaks
Q_r, Q_cb, Q_ct = ck_test_known_breaks(
y, x,
model=2,
break_dates=[100], # Known break at t=100
klags=2,
kleads=2
)
Unknown Break Dates
from co_eco import ck_test_unknown_1break, ck_test_unknown_2breaks
# One unknown break
Q_r, Q_cb, Q_ct, Tbhat = ck_test_unknown_1break(y, x, model=2, klags=2, kleads=2)
# Two unknown breaks
Q_r, Q_cb, Q_ct, Tbhat = ck_test_unknown_2breaks(y, x, model=2, klags=2, kleads=2)
Using the CKTest Class
from co_eco import CKTest
test = CKTest(y, x, model=2, klags=2, kleads=2)
# Run for specific number of breaks
results_1break = test.run(num_breaks=1)
print(results_1break.is_cointegrated(0.05)) # True if CI holds at 5% level
# Run for all break specifications (0, 1, 2)
all_results = test.run_all(max_breaks=2)
# Run Dmax tests
dmax_cb, dmax_ct = test.run_dmax(max_breaks=2)
print(dmax_cb)
Output Formats
# Get summary
print(results.summary())
# Get LaTeX table
latex_table = results.to_latex()
# Get dictionary
results_dict = results.to_dict()
Example: US Budget Sustainability
from co_eco import CKTest
from co_eco.data import load_us_budget
# Load data
R, E, B = load_us_budget()
# Test for cointegration between expenditures and revenues
test = CKTest(E, R.reshape(-1, 1), model=2, klags=3, kleads=3)
# Run tests with 1 break
results = test.run(num_breaks=1)
print(results)
# Run tests with 2 breaks
results_2 = test.run(num_breaks=2)
print(results_2)
Critical Values
Critical values are provided for:
- Significance levels: 1%, 5%, 10%
- Number of breaks: 0, 1, 2
- Number of regressors: 1-5
- Both Model I and Model II
from co_eco import get_critical_values, get_lambda_bar
# Get critical value
cv = get_critical_values('robust_ci', m=1, model=2, px=1, significance_level=0.05)
# Get lambda bar parameter
lbar = get_lambda_bar(m=1, model=2, px=1)
API Reference
Main Functions
| Function | Description |
|---|---|
ck_test_known_breaks() |
Tests with known break dates |
ck_test_unknown_1break() |
Tests with one unknown break |
ck_test_unknown_2breaks() |
Tests with two unknown breaks |
dmax_cobreaking_test() |
Dmax test for cobreaking |
dmax_cotrending_test() |
Dmax test for cotrending |
Utility Functions
| Function | Description |
|---|---|
long_run_variance() |
HAC estimator with Andrews bandwidth |
dols_reg_maker() |
DOLS regressor matrix construction |
create_step_dummies() |
Step dummy variable creation |
Classes
| Class | Description |
|---|---|
CKTest |
Main class for running all tests |
CKTestResults |
Results container with formatting |
DmaxTestResults |
Dmax test results container |
Mathematical Background
The tests are based on quasi-likelihood ratio principles. Under the null hypothesis of cointegration:
$$y_t = \beta' x_t + \alpha' d_t + v_t$$
where:
- $y_t$ is the dependent variable
- $x_t$ are stochastic regressors (I(1))
- $d_t$ are deterministic components (intercepts, trends, step dummies)
- $v_t$ is I(0) under cointegration, I(1) under no cointegration
The test statistics are:
- Q_r: Robust CI test (invariant to break parameters)
- Q_cb: Joint test with $m \log(T)$ adjustment
- Q_ct: Joint test with additional adjustment for trend
Compatibility
This package is an exact translation of the original MATLAB code by Carrion-i-Silvestre and Kim (2019). Results should match the MATLAB implementation up to numerical precision.
Citation
If you use this package in your research, please cite:
@article{carrion2019quasi,
title={Quasi-likelihood ratio tests for cointegration, cobreaking, and cotrending},
author={Carrion-i-Silvestre, Josep Llu{\'\i}s and Kim, Dukpa},
journal={Econometric Reviews},
volume={38},
number={6},
pages={681--709},
year={2019},
publisher={Taylor \& Francis},
doi={10.1080/07474938.2018.1528416}
}
And this Python implementation:
@software{coeco2024,
author = {Roudane, Merwan},
title = {co-eco: Python implementation of Carrion-i-Silvestre and Kim (2019) cointegration tests},
year = {2024},
url = {https://github.com/merwanroudane/coeco}
}
References
- Carrion-i-Silvestre, J.L. and Kim, D. (2019). Quasi-likelihood ratio tests for cointegration, cobreaking, and cotrending. Econometric Reviews, 38(6), 681-709.
- Andrews, D.W.K. (1991). Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation. Econometrica, 59(3), 817-858.
- Saikkonen, P. (1991). Asymptotically Efficient Estimation of Cointegration Regressions. Econometric Theory, 7(1), 1-21.
Author
Dr Merwan Roudane
Email: merwanroudane920@gmail.com
GitHub: https://github.com/merwanroudane/coeco
License
MIT License - see LICENSE for details.
Metadata
Release files for co-eco 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| co_eco-0.0.1.tar.gz | 32.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| co_eco-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.5 kB
Release files / co_eco-0.0.1.tar.gz
| Download URL | co_eco-0.0.1.tar.gz |
|---|---|
| Size | 32.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ace380ee46228bb10902aa02d5620e04d39102ad421e77c2f13b6c1bace6e3bd
|
|
BLAKE2b-256 checksum How to use checksums |
c5b520c2d661e8e8749633f114aceb6322cd9aca1a4b06e80425f96813ff9978
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / co_eco-0.0.1-py3-none-any.whl
| Download URL | co_eco-0.0.1-py3-none-any.whl |
|---|---|
| Size | 29.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55c26d171024af7209430a0867ac4f4f43d6f5fff4a1c9cc76573b23e3c63fdb
|
|
BLAKE2b-256 checksum How to use checksums |
ee59cab91dfe80d1746f47542f02fc61f794e89aad3db59834afb5eb68c1ef1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for co-eco 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.