Quantile Autoregressive Distributed Lag (QARDL) Models - GAUSS/MATLAB Compatible
Project description
QARDL - Quantile Autoregressive Distributed Lag Models
Version 1.0.3 - GAUSS/MATLAB Compatible Implementation
Exact Python implementation of the QARDL methodology from:
Cho, J.S., Kim, T.-H., & Shin, Y. (2015). Quantile cointegration in the autoregressive distributed-lag modeling framework. Journal of Econometrics, 188(1), 281-300.
Features
- ✅ GAUSS Compatible: Design matrix construction matches original GAUSS
qardl.srcexactly - ✅ Correct Long-run Formula: β = θ₀ / (1 - Σφ) using only current X coefficient
- ✅ Proper Wald Tests: Exact scaling factors
(n-1)²for long-run,(n-1)for short-run - ✅ ECM Representation: MATLAB
qardlecm.mcompatible Error Correction Model - ✅ Rolling Estimation:
rollingQardlwith Wald tests at each window - ✅ Simulation:
qardlAR2Simfor Monte Carlo experiments - ✅ Plotting:
plotQARDLequivalent visualization - ✅ BIC Lag Selection: Automatic optimal (p, q) selection
Installation
pip install qardl
Or from source:
pip install -e .
Quick Start
import numpy as np
from qardl import qardl, QARDL, pq_order
# Prepare data: [y | X1 | X2 | ...]
data = np.column_stack([y, X])
# Select optimal lag orders
p_opt, q_opt = pq_order(data, p_max=7, q_max=7)
print(f"Optimal lags: p={p_opt}, q={q_opt}")
# Estimate QARDL model
tau = np.array([0.10, 0.25, 0.50, 0.75, 0.90])
qaOut = qardl(data, p_opt, q_opt, tau)
# Results
print("Long-run β:", qaOut.bigbt)
print("Short-run φ:", qaOut.phi)
print("Short-run γ:", qaOut.gamma)
print(qaOut.summary())
Wald Tests
from qardl import wtestlrb, wtestsrp, wtestsrg
# Define restrictions: R * β = r
# Example: Test β₁(τ₁) = β₁(τ₂)
R = np.zeros((1, len(qaOut.bigbt)))
R[0, 0] = 1 # β₁(τ₁)
R[0, k] = -1 # β₁(τ₂)
r = np.zeros(1)
# Long-run parameter test (uses (n-1)² scaling)
wt, pv = wtestlrb(qaOut.bigbt, qaOut.bigbt_cov, R, r, data)
print(f"Wald statistic: {wt:.4f}, p-value: {pv:.4f}")
# Short-run tests (use (n-1) scaling)
wt_phi, pv_phi = wtestsrp(qaOut.phi, qaOut.phi_cov, R_phi, r_phi, data)
wt_gam, pv_gam = wtestsrg(qaOut.gamma, qaOut.gamma_cov, R_gam, r_gam, data)
Rolling QARDL Estimation
from qardl import rolling_qardl, create_wald_restrictions
# Create Wald test restrictions
tau = np.array([0.25, 0.50, 0.75])
wctl = create_wald_restrictions(k=2, p_max=7, num_tau=len(tau))
# Run rolling estimation
rqaOut = rolling_qardl(data, p_max=7, q_max=7, tau=tau, wctl=wctl)
# Results
print(f"Window size: {rqaOut.window_size}")
print(f"Beta array shape: {rqaOut.bigbt.shape}") # (k x num_est x num_tau)
# Get specific estimates
beta1_05 = rqaOut.get_beta(var_idx=0, tau_idx=1) # β₁(τ=0.5)
# Wald test results
print("Wald beta:", rqaOut.rWaldOut.wald_beta)
ECM Representation
from qardl import qardl_ecm, QARDLECM
# Direct ECM estimation
ecmOut = qardl_ecm(data, p, q, tau)
# Results
print("Adjustment speed (ζ):", ecmOut.zeta)
print("Long-run β:", ecmOut.beta)
print("Half-life:", ecmOut.get_half_life(0)) # For first quantile
Simulation
from qardl import qardl_ar2_sim, DGPParams, simulate_wald_tests
# Generate QARDL data (matches GAUSS qardlAR2Sim)
y, X = qardl_ar2_sim(n=500, alpha=1.0, phi=0.25, rho=0.5,
theta0=2.0, theta1=3.0, seed=42)
# With custom parameters
params = DGPParams(alpha=1.0, phi=0.25, theta0=2.0, theta1=3.0)
print(f"Long-run β = {params.beta:.4f}")
# Monte Carlo simulation for Wald test size
results = simulate_wald_tests(n=500, n_iter=1000, p=1, q=2,
tau=np.array([0.2, 0.4, 0.6, 0.8]))
Plotting
from qardl import plot_qardl, plot_beta, plot_rolling
# Plot all parameters
fig = plot_qardl(qaOut)
plt.show()
# Plot with confidence intervals
fig = plot_beta(qaOut, with_ci=True, alpha=0.05)
plt.show()
# Plot rolling results
fig = plot_rolling(rqaOut, var_idx=0, tau_idx=1, param_type='beta')
plt.show()
Design Matrix Structure
The design matrix follows GAUSS ordering exactly:
ONEX = [1 | eei | xxi | yyi]
Where:
1: Intercepteei: Lagged first differences of X (Δx_{t}, Δx_{t-1}, ..., Δx_{t-q+1})xxi: Current levels of X (x_t)yyi: Lagged dependent variable (y_{t-1}, ..., y_{t-p})
Complete Function Reference
Core Estimation
| Function | Description | GAUSS Equivalent |
|---|---|---|
qardl(data, p, q, tau) |
Main QARDL estimation | qardl() |
QARDL class |
OOP interface | - |
pq_order(data, p_max, q_max) |
BIC lag selection | pqorder() |
Wald Tests
| Function | Description | GAUSS Equivalent |
|---|---|---|
wtestlrb() |
Long-run β test | wtestlrb.src |
wtestsrp() |
Short-run φ test | wtestsrp.src |
wtestsrg() |
Short-run γ test | wtestsrg.src |
Rolling Estimation
| Function | Description | GAUSS Equivalent |
|---|---|---|
rolling_qardl() |
Rolling window estimation | rollingQardl() |
create_wald_restrictions() |
Create restriction matrices | - |
ECM
| Function | Description | MATLAB Equivalent |
|---|---|---|
qardl_ecm() |
ECM estimation | qardlecm.m |
convert_qardl_to_ecm() |
Convert QARDL to ECM params | - |
Simulation
| Function | Description | GAUSS Equivalent |
|---|---|---|
qardl_ar2_sim() |
Generate QARDL data | qardlAR2Sim() |
generate_qardl_data() |
Flexible data generation | - |
simulate_wald_tests() |
Monte Carlo simulation | wald_tests_sim.e |
Plotting
| Function | Description | GAUSS Equivalent |
|---|---|---|
plot_qardl() |
Plot all parameters | plotQARDL() |
plot_beta() |
Plot long-run with CI | plotBetaGraphs() |
plot_gamma() |
Plot short-run γ | plotGammaGraphs() |
plot_phi() |
Plot AR φ | plotPhiGraphs() |
plot_rolling() |
Plot rolling results | - |
Output Structure (matches GAUSS)
| Output | Description | Dimension |
|---|---|---|
bigbt |
Long-run parameters β | (k×s) × 1 |
bigbt_cov |
Covariance of β | (k×s) × (k×s) |
phi |
Short-run AR parameters φ | (p×s) × 1 |
phi_cov |
Covariance of φ | (p×s) × (p×s) |
gamma |
Short-run impact parameters γ | (k×s) × 1 |
gamma_cov |
Covariance of γ | (k×s) × (k×s) |
Where k = number of X variables, s = number of quantiles, p = AR order.
Citation
If you use this package, please cite:
@article{cho2015quantile,
title={Quantile cointegration in the autoregressive distributed-lag modeling framework},
author={Cho, Jin Seo and Kim, Tae-hwan and Shin, Yongcheol},
journal={Journal of Econometrics},
volume={188},
number={1},
pages={281--300},
year={2015},
publisher={Elsevier}
}
Author
Dr. Merwan Roudane
Email: merwanroudane920@gmail.com
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qardl-1.0.6.tar.gz.
File metadata
- Download URL: qardl-1.0.6.tar.gz
- Upload date:
- Size: 30.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1463fa7b2f5d9cfd6163717e1e342622cbc90e3e88f437db3b7e9c0b3665630e
|
|
| MD5 |
1d3e9e9fd89e8838b217ed503e25d686
|
|
| BLAKE2b-256 |
196fa1c905bcb253b97cdb42494eeb1fe9ee69b7943d9dfdfb03dabe99a97476
|
File details
Details for the file qardl-1.0.6-py3-none-any.whl.
File metadata
- Download URL: qardl-1.0.6-py3-none-any.whl
- Upload date:
- Size: 29.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29e133b9cbbcb9bd8271653742df46b836c1dbb9f5248825c248d5f581db90be
|
|
| MD5 |
e8759195f12e8f2ac19b6efab6cdfa9a
|
|
| BLAKE2b-256 |
3635d223e7af575e03aebeae4142e7fe6f149191c8d1dded183f27a0b5b87fed
|