High-Dimensional Cointegration and Impulse Response Harness
Build an automated Python pipeline script for Johansen cointegration testing, VECM specification, and bootstrapped impulse response estimation.
Deploy this template when evaluating long-run equilibrium relationships across non-stationary macroeconomic or financial time series. It produces production-ready, object-oriented Python code for statistical validation.
Role: Lead Financial Econometrician and Quantitative Macro-Modeler
Context
- System Endogenous Variables: {{time_series_variables}}
- Model Order Selection Rule: {{lag_order_criterion}}
- Rank Determination Critical Value: {{cointegration_rank_threshold}}
- Resampling Iterations: {{bootstrap_replications_count}}
- Dynamics Horizon: {{forecast_horizon_periods}}
Task
Develop an industrial-grade, object-oriented Python script utilizing statsmodels and numpy to ingest multivariate time series, evaluate integration orders, estimate a Vector Error Correction Model (VECM), and output orthogonalized, bootstrapped impulse response functions with empirical confidence bands.
Method
- Define an ingest module that validates stationarity using Augmented Dickey-Fuller (ADF) and Phillips-Perron (PP) tests for {{time_series_variables}}.
- Implement optimal VAR lag length selection algorithm evaluating up to maximum 12 lags guided by {{lag_order_criterion}}.
- Conduct Johansen cointegration tests (Trace and Max-Eigenvalue) at {{cointegration_rank_threshold}} to determine cointegrating rank $r$.
- Parameterize and estimate the constrained VECM representation, extracting the adjustment speeds (alpha) and long-run cointegrating vectors (beta).
- Compute residuals and verify absence of serial autocorrelation using Breusch-Godfrey Lagrange Multiplier tests.
- Construct a wild/residual bootstrap engine with {{bootstrap_replications_count}} resamples to generate non-parametric confidence bands.
- Propagate structural shocks across {{forecast_horizon_periods}} to calculate orthogonalized Impulse Response Functions (OIRF).
- Implement automated validation logging and visualization plotting module using
matplotlib.
Constraints
- Code MUST be fully runnable Python 3.10+ wrapped in a modular class structure with type hints and docstrings.
- Data input pipeline MUST NOT fail on missing timestamps, implementing strict forward-fill or interpolation guards.
- All bootstrap loops MUST be vectorized or accelerated using multiprocessing to avoid single-thread bottlenecks.
- MUST validate that cointegration rank $r > 0$ before proceeding to VECM; otherwise, fallback to difference-stationary VAR.
Output format
Deliver the analysis pipeline structured in the following sections:
- Theoretical Specification: A 150-word mathematical summary outlining the error-correction formulation and identification strategy.
- Complete Python Script: Well-commented, modular code containing
TimeSeriesPreprocessor,VECMEngine, andBootstrapIRFclasses with a runnable__main__demonstration block. - Metric Interpretation Key: A markdown guide explaining how to interpret alpha speed vectors and persistent versus transitory IRF trajectories.
Self-review
- Ensure the cointegration test accommodates both deterministic trend and intercept options correctly.
- Verify that the bootstrap engine respects temporal dependence without data leakage.
- Confirm that impulse response confidence bands are computed accurately at 95% and 68% coverage levels based on {{bootstrap_replications_count}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.