"""
MixVECM: Vector Error Correction Models with Mixed I(0) and I(1) Variables
===========================================================================

A Python implementation of the methodology presented in:
Chen, P. (2022). "Vector Error Correction Models with Stationary and 
Nonstationary Variables". SSRN Working Paper 4239531.

This package extends the standard VECM framework to accommodate systems
containing both I(1) and I(0) time series variables.

Key Features
------------
- Mixed VECM estimation with both I(0) and I(1) variables
- Johansen cointegration test with I(0) space dimension determination
- Likelihood ratio tests for I(0) components
- Restricted beta estimation using Boswijk and Doornik (2004) iterative procedure
- Data generation for Monte Carlo simulations
- Impulse response function analysis
- Publication-ready output formatting

Mathematical Framework
----------------------
The standard VECM is formulated as:

    ΔY_t = αβ'Y_{t-1} + Σ Π_l ΔY_{t-l} + U_t

This package extends this to handle cases where Y_t contains both I(1) and I(0)
components. The key insight is that a mixed VECM can be viewed as a cointegrated
VECM with restrictions on the cointegrating space.

Lemma (Chen, 2022): The necessary and sufficient condition for a VECM to contain
k I(0) variables is that the cointegrating matrix β can be written as:

    β' = [[B21, B22, 0], [0, 0, B33]]

where the two subspaces (cointegration relations and I(0) variables) are orthogonal.

Author: Dr Merwan Roudane
Email: merwanroudane920@gmail.com
GitHub: https://github.com/merwanroudane/mixvecm

References
----------
[1] Chen, P. (2022). Vector Error Correction Models with Stationary and 
    Nonstationary Variables. SSRN Working Paper 4239531.
[2] Johansen, S. (1995). Likelihood-Based Inference in Cointegrated Vector
    Autoregressive Models. Oxford University Press.
[3] Boswijk, H.P. and Doornik, J.A. (2004). Identifying, estimating and testing
    restricted cointegrated systems: An overview. Statistica Neerlandica.
"""

__version__ = "1.0.2"
__author__ = "Dr Merwan Roudane"
__email__ = "merwanroudane920@gmail.com"

from .core import (
    MixedVECM,
    MixedVECMResults,
    estimate_mixed_vecm,
    fit_vecm,
)

from .testing import (
    johansen_test,
    JohansenTestResults,
    test_i0_components,
    I0ComponentTestResults,
    select_cointegration_rank,
    likelihood_ratio_test,
    LRTestResults,
)

from .datagen import (
    generate_mixed_vecm_data,
    DataGenerationResult,
    example_dgp_1,
    example_dgp_2,
    generate_from_underlying_var,
    generate_from_restricted_beta,
)

from .irf import (
    compute_irf,
    IRFResults,
    compute_orthogonalized_irf,
    compute_fevd,
    FEVDResults,
)

from .utils import (
    vec,
    unvec,
    lag_matrix,
    diff_matrix,
    compute_residuals,
    compute_aic_bic,
    select_lag_order,
    orthogonal_complement,
    normalize_beta,
)

__all__ = [
    # Version info
    "__version__",
    "__author__",
    "__email__",
    # Core classes and functions
    "MixedVECM",
    "MixedVECMResults", 
    "estimate_mixed_vecm",
    "fit_vecm",
    # Testing
    "johansen_test",
    "JohansenTestResults",
    "test_i0_components",
    "I0ComponentTestResults",
    "select_cointegration_rank",
    "likelihood_ratio_test",
    "LRTestResults",
    # Data generation
    "generate_mixed_vecm_data",
    "DataGenerationResult",
    "example_dgp_1",
    "example_dgp_2",
    "generate_from_underlying_var",
    "generate_from_restricted_beta",
    # Impulse response functions
    "compute_irf",
    "IRFResults",
    "compute_orthogonalized_irf",
    "compute_fevd",
    "FEVDResults",
    # Utilities
    "vec",
    "unvec",
    "lag_matrix",
    "diff_matrix",
    "compute_residuals",
    "compute_aic_bic",
    "select_lag_order",
    "orthogonal_complement",
    "normalize_beta",
]
