QADF - Quantile ADF Unit Root Test
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:
- t-statistic
tₙ(τ): The quantile regression counterpart of the ADF t-ratio - Coefficient statistic
Uₙ(τ) = n(ρ̂₁(τ) - 1): Coefficient-based test - QKS statistics: Kolmogorov-Smirnov type tests over quantile range
- 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 resultsQADFProcessResult: Multiple quantile test resultsBootstrapResult: Bootstrap inference results
Examples
See the examples/ directory for:
example_basic.py: Basic usage examplesexample_interest_rates.py: Replication of interest rate analysisexample_monte_carlo.py: Monte Carlo simulation studies
Compatibility
This implementation maintains exact compatibility with:
- Original paper methodology: Koenker & Xiao (2004)
- GAUSS code: By Saban Nazlioglu (TSPDLIB package)
- 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
- Email: merwanroudane920@gmail.com
- GitHub: https://github.com/merwanroudane
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
Metadata
Release files for qadf 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| qadf-1.0.0.tar.gz | 31.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qadf-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 60.5 kB
Release files / qadf-1.0.0.tar.gz
| Download URL | qadf-1.0.0.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b6ba9cd35a66da2ea6dfa63113b4e80b4ce849076e3b7f7739337cba545e58f
|
|
BLAKE2b-256 checksum How to use checksums |
364b3f4378710d24d28f1f9eea8791970d5327a06b58187ee27a53949fdbe112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / qadf-1.0.0-py3-none-any.whl
| Download URL | qadf-1.0.0-py3-none-any.whl |
|---|---|
| Size | 29.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c3bc3ee7df50d0dbf649c1e8bd6092b97bef505ceaf9376708226d3f8993c7d
|
|
BLAKE2b-256 checksum How to use checksums |
fbb841052d6d8b77db721e843bfee016fad261faa3aa262b16672d691e31c71b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for qadf 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.