Skip to main content

Quantile ADF Unit Root Test - Implementation of Koenker & Xiao (2004)

Project description

QADF - Quantile ADF Unit Root Test

PyPI version Python 3.8+ License: MIT

A Python implementation of the Quantile Autoregression Unit Root Test proposed by Koenker & Xiao (2004).

Overview

This package implements the quantile autoregression-based unit root test, which provides:

  • Robust inference under non-Gaussian disturbances (heavy-tailed distributions)
  • Asymmetric dynamics detection - the ability to detect different persistence patterns at different quantiles
  • Power gains over conventional ADF tests with non-normal errors
  • Publication-ready output and visualization tools

Reference

Koenker, R., Xiao, Z. (2004). Unit Root Quantile Autoregression Inference.
Journal of the American Statistical Association, 99, 775-787.
DOI: 10.1198/016214504000001114

Installation

pip install qadf

Or install from source:

git clone https://github.com/merwanroudane/quantileadf.git
cd quantileadf
pip install -e .

Quick Start

Basic Usage

import numpy as np
from qadf import qadf, qadf_process

# Generate a random walk (unit root process)
np.random.seed(42)
y = np.cumsum(np.random.randn(200))

# Test at the median (τ = 0.5)
result = qadf(y, tau=0.5, model='c')
print(result)

Output:

======================================================================
         Quantile ADF Unit Root Test Results
======================================================================
Reference: Koenker, R., Xiao, Z. (2004). JASA, 99, 775-787.
----------------------------------------------------------------------
Model: Constant
Quantile (τ):           0.500
Number of observations: 197
Number of lags:         1
----------------------------------------------------------------------
                        Estimates
----------------------------------------------------------------------
ρ₁(τ) [QR]:             0.998521
ρ₁ [OLS]:               0.997843
α₀(τ):                  -0.023156
δ²:                     0.182456
Half-life:              ∞
----------------------------------------------------------------------
                     Test Statistics
----------------------------------------------------------------------
tₙ(τ):                  -0.8234
----------------------------------------------------------------------
                     Critical Values
----------------------------------------------------------------------
1% critical value:      -2.9139
5% critical value:      -2.2790
10% critical value:     -1.9172
======================================================================
Note: *** p<0.01, ** p<0.05, * p<0.10
H₀: Unit root (ρ₁ = 1) vs H₁: Stationarity (ρ₁ < 1)
======================================================================

Testing Across Multiple Quantiles

# Test across deciles (0.1, 0.2, ..., 0.9)
result = qadf_process(y, quantiles=np.arange(0.1, 1.0, 0.1))
print(result)

# Export to DataFrame
df = result.to_dataframe()
print(df)

Visualization

from qadf import plot_qadf_process, plot_coefficient_dynamics

# Visualize results
plot_qadf_process(result)
plot_coefficient_dynamics(result, title='Interest Rate Persistence')

Bootstrap Inference

from qadf import bootstrap_pvalue, bootstrap_critical_values

# Get bootstrap p-value
boot_result = bootstrap_pvalue(
    test_statistic=result.results[4].statistic,  # Median result
    y=y,
    tau=0.5,
    model='c',
    p=1,
    n_replications=1000
)

print(f"Bootstrap p-value: {boot_result.pvalue:.4f}")
print(f"Bootstrap 5% CV: {boot_result.critical_values['5%']:.4f}")

Model Specifications

The test supports two model specifications:

Model Description Default
'c' Constant only ✓ (Koenker & Xiao default)
'ct' Constant and linear trend

Test Statistics

The package computes:

  1. t-statistic tₙ(τ): The quantile regression counterpart of the ADF t-ratio
  2. Coefficient statistic Uₙ(τ) = n(ρ̂₁(τ) - 1): Coefficient-based test
  3. QKS statistics: Kolmogorov-Smirnov type tests over quantile range
  4. QCM statistics: Cramér-von Mises type tests over quantile range

Critical Values

Critical values are based on Hansen (1995), which tabulates critical values for the CADF test. The limiting distribution of the QADF test is:

tₙ(τ) → δ(∫₀¹ W̄₁²)^{-1/2} ∫₀¹ W̄₁dW₁ + √(1-δ²)N(0,1)

This is a mixture of the Dickey-Fuller distribution and the standard normal, with weights determined by δ (the long-run correlation coefficient).

API Reference

Main Functions

Function Description
qadf(y, tau, model, pmax, ic) Single quantile test
qadf_process(y, quantiles, model, pmax, ic) Multiple quantile test
bootstrap_pvalue(...) Bootstrap p-value
bootstrap_critical_values(...) Bootstrap CVs
get_hansen_critical_values(delta2, model) Hansen (1995) CVs

Result Objects

  • QADFResult: Single quantile test results
  • QADFProcessResult: Multiple quantile test results
  • BootstrapResult: Bootstrap inference results

Examples

See the examples/ directory for:

  • example_basic.py: Basic usage examples
  • example_interest_rates.py: Replication of interest rate analysis
  • example_monte_carlo.py: Monte Carlo simulation studies

Compatibility

This implementation maintains exact compatibility with:

  1. Original paper methodology: Koenker & Xiao (2004)
  2. GAUSS code: By Saban Nazlioglu (TSPDLIB package)
  3. Hansen (1995) critical values: CADF test tables

Citation

If you use this package in your research, please cite:

@article{koenker2004unit,
  title={Unit Root Quantile Autoregression Inference},
  author={Koenker, Roger and Xiao, Zhijie},
  journal={Journal of the American Statistical Association},
  volume={99},
  number={467},
  pages={775--787},
  year={2004},
  publisher={Taylor \& Francis},
  doi={10.1198/016214504000001114}
}

@software{qadf2024,
  title={QADF: Quantile ADF Unit Root Test for Python},
  author={Roudane, Merwan},
  year={2024},
  url={https://github.com/merwanroudane/quantileadf}
}

Author

Dr Merwan Roudane

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Roger Koenker and Zhijie Xiao for the original methodology
  • Bruce Hansen for the CADF critical values
  • Saban Nazlioglu for the GAUSS implementation reference

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

qadf-1.0.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

qadf-1.0.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file qadf-1.0.0.tar.gz.

File metadata

  • Download URL: qadf-1.0.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for qadf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3b6ba9cd35a66da2ea6dfa63113b4e80b4ce849076e3b7f7739337cba545e58f
MD5 55bf4470d01ac69bdfd43de0e6bc3b1f
BLAKE2b-256 364b3f4378710d24d28f1f9eea8791970d5327a06b58187ee27a53949fdbe112

See more details on using hashes here.

File details

Details for the file qadf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: qadf-1.0.0-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 qadf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3bc3ee7df50d0dbf649c1e8bd6092b97bef505ceaf9376708226d3f8993c7d
MD5 abe391c7e4cca95a5e68e36c929324f4
BLAKE2b-256 fbb841052d6d8b77db721e843bfee016fad261faa3aa262b16672d691e31c71b

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