Skip to main content

cointhatemij

Hatemi-J Cointegration Test with Two Unknown Regime Shifts

A Python implementation of the Hatemi-J (2008) cointegration test that allows for two structural breaks with unknown timing.

Reference

Hatemi-J, A. (2008). Tests for cointegration with two unknown regime shifts with an application to financial market integration. Empirical Economics, 35, 497-505. DOI: 10.1007/s00181-007-0175-9

Features

  • ✅ Three test statistics (ADF, Zt, Za)
  • ✅ Endogenous detection of two structural breaks
  • ✅ Multiple lag selection criteria (AIC, BIC, t-stat)
  • ✅ Various variance estimation methods
  • ✅ Critical values for k ≤ 4 independent variables
  • ✅ Fully validated against original paper

Installation

pip install cointhatemij

Quick Start

import numpy as np
from cointhatemij import coint_hatemi_j

# Your data
y = np.array([...])  # Dependent variable
x = np.array([...])  # Independent variable(s)

# Run test
results = coint_hatemi_j(y, x)

# Check results
print(f"ADF statistic: {results['ADF_min']:.3f}")
print(f"Break dates: {results['TB1_adf']}, {results['TB2_adf']}")

Usage Example

import numpy as np
from cointhatemij import HatemiJTest

# Generate sample data
np.random.seed(123)
n = 100
x = np.random.randn(n, 2)
y = 0.5 + 0.3 * x[:, 0] + 0.2 * x[:, 1] + np.random.randn(n)

# Create test instance
test = HatemiJTest(y, x, 
                   model=3,      # Only model 3 available
                   ic=3,         # t-stat lag selection
                   pmax=8,       # Maximum 8 lags
                   varm=1,       # iid variance
                   trimm=0.10)   # 10% trimming

# Run test
results = test.fit()

# Display results
test.summary()

Parameters

  • y: Dependent variable (n × 1)
  • x: Independent variables (n × k), where k ≤ 4
  • model: Model specification (only 3 available)
  • ic: Information criterion (1=AIC, 2=BIC, 3=t-stat)
  • pmax: Maximum lags for ADF test (default: 8)
  • varm: Variance method (1=iid, 2=Bartlett, 3=QS)
  • trimm: Trimming rate (default: 0.10)

Output

Returns dictionary with:

  • ADF_min, Zt_min, Za_min: Test statistics
  • TB1_adf, TB2_adf: Break dates (ADF)
  • TB1_zt, TB2_zt: Break dates (Zt)
  • TB1_za, TB2_za: Break dates (Za)
  • cv_adf_zt, cv_za: Critical values

Critical Values

From Hatemi-J (2008), Table 1:

k Test 1% 5% 10%
1 ADF/Zt -6.503 -6.015 -5.653
2 ADF/Zt -6.928 -6.458 -6.224
3 ADF/Zt -7.833 -7.352 -7.118
4 ADF/Zt -8.353 -7.903 -7.705

Methodology

The test is based on the model:

y_t = α_0 + α_1*D1_t + α_2*D2_t + β_0'*x_t + β_1'*D1_t*x_t + β_2'*D2_t*x_t + u_t

Where D1_t and D2_t are dummy variables for two structural breaks. Break dates are estimated endogenously, and three test statistics are computed as the minimum values across all possible break combinations.

Null hypothesis: No cointegration

Testing

# Run tests
pytest tests/ -v

# Run validation
python validate.py

Citation

@article{hatemi2008tests,
  title={Tests for cointegration with two unknown regime shifts},
  author={Hatemi-J, Abdulnasser},
  journal={Empirical Economics},
  volume={35},
  pages={497--505},
  year={2008}
}

@software{roudane2024cointhatemij,
  author = {Roudane, Merwan},
  title = {cointhatemij: Python implementation of Hatemi-J test},
  year = {2024},
  url = {https://github.com/merwanroudane/cointhatemij}
}

License

MIT License - see LICENSE file for details.

Author

Dr. Merwan Roudane

Support

Metadata

Release files for cointhatemij 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cointhatemij 0.1.5
File Size Uploaded Provenance
cointhatemij-0.1.5.tar.gz 15.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cointhatemij 0.1.5
File Interpreter ABI Platform
cointhatemij-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / cointhatemij-0.1.5.tar.gz

Download URL cointhatemij-0.1.5.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5776baf33a000368f71dc0f2d772ffe823db442b0f50bf31705443d04d9bb911
BLAKE2b-256 checksum
How to use checksums
bfb6a2f0467a39a78166d79b531e799abc5dc42118006d181c5453ad9a2aa1a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / cointhatemij-0.1.5-py3-none-any.whl

Download URL cointhatemij-0.1.5-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1874274b986da96d7b09088ebf7c1c3c750fae83424cc5f97f8add97ce6ffe9e
BLAKE2b-256 checksum
How to use checksums
25fbf11dbde7409e8ebe0371fb314f787a467db03a87fd4b1e742dc4eec8503b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for cointhatemij 0.1.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page