segmcoint
Tests for Segmented Cointegration
A Python library implementing rigorous tests for segmented cointegration from two seminal econometric papers:
- Kim, J.-Y. (2003). Inference on Segmented Cointegration. Econometric Theory, 19, 620–639.
- Martins, L.F. and Rodrigues, P.M.M. (2022). Tests for Segmented Cointegration: An Application to US Governments Budgets. Empirical Economics, 63, 567–600.
Overview
Cointegration relations are often interpreted as long-run equilibrium relationships. In practice, however, real data frequently fail to confirm cointegration for well-understood economic relations. This package addresses the possibility that failure to confirm cointegration is due to nonstationary deviations in a relatively small portion of the data ("short-run"), while the cointegration relation prevails in the remaining periods—a situation called segmented cointegration.
Kim (2003) Tests
- Phillips–Perron–Ouliaris type tests: $Z^_\rho(\mathcal{C})$ and $Z^_t(\mathcal{C})$
- Augmented Dickey–Fuller type tests: $ADF^_\rho(\mathcal{C})$ and $ADF^_t(\mathcal{C})$
- Extremum estimator for break date identification (Eq. 3.16–3.17)
- Critical values from Tables 1 and 2 of the paper (for $\bar{\ell}(\mathcal{T}_N) = 0.3$)
Martins & Rodrigues (2022) Tests
- Wald-type statistics: $F_A(\tau, m^)$ and $F_B(\tau, m^)$ (Eq. 3.2)
- Supremum statistics: $\sup F_A(m^)$ and $\sup F_B(m^)$ (Eq. 3.3)
- Combined test: $W(m^*)$ (Eq. 3.4)
- Double maximum test: $W_{\max}$ (Eq. 3.5)
- Critical values from Table 1 of the paper
- Break date estimation (Remark 3)
Installation
pip install .
Or for development:
pip install -e ".[dev]"
Quick Start
import numpy as np
from segmcoint import kim_test, mr_test, generate_segmented_data
# Generate data with segmented cointegration
y, X, eps, info = generate_segmented_data(T=200, rho=0.85, seed=42)
# Kim (2003) tests
res_kim = kim_test(y, X, model='drift')
print(res_kim)
# Martins & Rodrigues (2022) tests
res_mr = mr_test(y, X, model='drift')
print(res_mr)
Model Specifications
Three deterministic specifications are supported, following Kim (2003, Eq. 2.1a–2.1c):
| Model | Equation | Kim (2003) | M&R (2022) |
|---|---|---|---|
'none' |
$x_{1t} = \beta' x_{2t} + \varepsilon_t$ | Case I | No det. |
'drift' |
$x_{1t} = \alpha + \beta' x_{2t} + \varepsilon_t$ | Case II | Intercept |
'trend' |
$x_{1t} = \alpha + \gamma t + \beta' x_{2t} + \varepsilon_t$ | Case III | Int.+Trend |
API Reference
kim_test(y, X, model, max_ell, step, ...)
Computes the infimum test statistics from Kim (2003). Returns a KimTestResult object.
mr_test(y, X, model, max_breaks, epsilon, step, ...)
Computes the Wald-type test statistics from Martins & Rodrigues (2022). Returns an MRTestResult object.
kim_break_estimator(y, X, model, max_ell, step)
Extremum estimator for the noncointegration period (Kim 2003, Eq. 3.16–3.17).
generate_segmented_data(T, beta, rho, ...)
Generate simulated data from a segmented cointegration DGP.
Testing
pytest tests/ -v
Author
Dr Merwan Roudane
Email: merwanroudane920@gmail.com
GitHub: https://github.com/merwanroudane/segmcoint
License
MIT License
References
- Kim, J.-Y. (2003). Inference on Segmented Cointegration. Econometric Theory, 19, 620–639.
- Martins, L.F. and Rodrigues, P.M.M. (2022). Tests for Segmented Cointegration: An Application to US Governments Budgets. Empirical Economics, 63, 567–600.
- Phillips, P.C.B. and Ouliaris, S. (1990). Asymptotic Properties of Residual Based Tests for Cointegration. Econometrica, 58, 165–193.
- Kejriwal, M., Perron, P., and Zhou, J. (2013). Wald Tests for Detecting Multiple Structural Changes in Persistence. Econometric Theory, 29, 289–323.
Metadata
Release files for segmcoint 1.0.0
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 | |
|---|---|---|---|---|
| segmcoint-1.0.0.tar.gz | 26.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| segmcoint-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.3 kB
Release files / segmcoint-1.0.0.tar.gz
| Download URL | segmcoint-1.0.0.tar.gz |
|---|---|
| Size | 26.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b71a233b781aef223a4241ff70cabf2cabf793eb5b6162fe9b93a9634ffcf4dd
|
|
BLAKE2b-256 checksum How to use checksums |
9cbdd8689123992f249c0312464028fe363dcd379d9c040eb38d44f2343600a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / segmcoint-1.0.0-py3-none-any.whl
| Download URL | segmcoint-1.0.0-py3-none-any.whl |
|---|---|
| Size | 25.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e2e7aca220c1731cf790847a1d84ce7abc3bb29a74561f83b77846d73b15a1b
|
|
BLAKE2b-256 checksum How to use checksums |
4be4b23fc8fac68131c8c7039debb6e2639de6ef6ed69a426b4a40b3c3f87767
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for segmcoint 1.0.0
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.