Skip to main content

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.src exactly
  • 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.m compatible Error Correction Model
  • Rolling Estimation: rollingQardl with Wald tests at each window
  • Simulation: qardlAR2Sim for Monte Carlo experiments
  • Plotting: plotQARDL equivalent 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: Intercept
  • eei: 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

qardl-1.0.5.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qardl-1.0.5-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file qardl-1.0.5.tar.gz.

File metadata

  • Download URL: qardl-1.0.5.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

Hashes for qardl-1.0.5.tar.gz
Algorithm Hash digest
SHA256 9b1d14edc08f7f7dfce42abd0f77b16fcd29a7479e6b81856cb9047d47c4e2fa
MD5 c439542d8d8c14b520d0cbf99cf65f9c
BLAKE2b-256 a3787e5bac02d119dec6daa3fda96548c28083dfd1a472f616b69b5f34f5fec2

See more details on using hashes here.

File details

Details for the file qardl-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: qardl-1.0.5-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

Hashes for qardl-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dcac0860960377455d11747c3dcfcdc1d2455e78218103bc86a2419f7170cf9a
MD5 cb75841c6287b2df9053694ca5d12c35
BLAKE2b-256 22b7e4e2d413cdedb49de3de36bb9131fd0858948427c45aeda04255c905f9ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page