Skip to content

vlad-yeghiazaryan/QADF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QADF

The module provides access to a quantile augmented Dickey-Fuller unit root procedure. The test performs unit root quantile autoregression inference following the Koenker and Xiao (2004) methodology.

Parts of the code/logic such as formulas for the bandwidth and critical values (Hansen, 1995) were written using the qradf function (by Saban Nazlioglu) in the Aptech GAUSS tspdlib library as a reference.

Usage

y = pd.read_csv('data/examples.csv', index_col=0, squeeze=True)
y.index = pd.date_range('2000-01-01', '2020-11-01', freq='MS')
qADF = QADF(y, model='c', pmax=5, ic='AIC')
qADF.fit(tau=0.42)
qADF.summary()
quantile: 0.42
Lags: 2
α₀(τ): 2.15
ρ₁(τ): 0.973
ρ₁(OLS): 0.968
δ²: 0.278
Half-lives: 25.461
tₙ(τ): -2.916
CV10%: -2.0271
CV5%: -2.3735
CV1%: -3.0307

Notebook example

import numpy as np
import pandas as pd
import time
import matplotlib.pyplot as plt
from quantileADF import QADF, bootstraps

import warnings
from statsmodels.tools.sm_exceptions import IterationLimitWarning
warnings.simplefilter('ignore', IterationLimitWarning)
y = pd.read_csv('data/examples.csv', index_col=0, squeeze=True)
y.index = pd.date_range('2000-01-01', '2020-11-01', freq='MS')
y.head()
2000-01-01    74.340017
2000-02-01    75.456058
2000-03-01    78.506961
2000-04-01    80.907992
2000-05-01    84.377459
Freq: MS, Name: Ukraine, dtype: float64
qADF = QADF(y, model='c', pmax=5, ic='AIC')
qADF.fit(tau=0.42)
qADF.summary()
quantile: 0.42
Lags: 2
α₀(τ): 2.15
ρ₁(τ): 0.973
ρ₁(OLS): 0.968
δ²: 0.278
Half-lives: 25.461
tₙ(τ): -2.916
CV10%: -2.0271
CV5%: -2.3735
CV1%: -3.0307
quantiles = np.arange(0.1, 1, 0.1)
CountryQADF = qADF.fitForQuantiles(quantiles)
CountryQADF
Lags α₀(τ) ρ₁(τ) ρ₁(OLS) δ² Half-lives tₙ(τ) CV10% CV5% CV1% QKS name
quantile
0.1 2 -2.304 1.002 0.968 0.328 0.058 -2.0885 -2.4298 -3.0839 2.681 Ukraine
0.2 2 -0.096 0.991 0.968 0.307 73.523 -0.558 -2.0646 -2.4066 -3.0678 2.681 Ukraine
0.3 2 1.330 0.978 0.968 0.289 31.646 -2.061 -2.0415 -2.3858 -3.0460 2.681 Ukraine
0.4 2 2.021 0.974 0.968 0.280 26.503 -2.681 -2.0288 -2.3749 -3.0325 2.681 Ukraine
0.5 2 2.219 0.975 0.968 0.277 27.527 -2.512 -2.0251 -2.3718 -3.0285 2.681 Ukraine
0.6 2 2.597 0.976 0.968 0.266 28.12 -2.016 -2.0096 -2.3585 -3.0121 2.681 Ukraine
0.7 2 3.391 0.972 0.968 0.250 24.476 -2.058 -1.9867 -2.3388 -2.9878 2.681 Ukraine
0.8 2 2.856 0.986 0.968 0.228 48.461 -0.969 -1.9559 -2.3123 -2.9550 2.681 Ukraine
0.9 2 4.874 0.973 0.968 0.168 24.866 -1.232 -1.8653 -2.2276 -2.8731 2.681 Ukraine
repetitions = 1000
boots = bootstraps(y, lags=2, n_replications=repetitions)
pd.DataFrame(boots).plot(kind='line', legend=False, figsize=(10,5))
y.plot(legend=True, color='black')
plt.show()

png

%%time
results = pd.concat([qADF.setup(boots[yStar]).fitForQuantiles(quantiles) for yStar in boots])
CPU times: user 19min 33s, sys: 12min 33s, total: 32min 6s
Wall time: 18min 2s
cvQKS = results.groupby('name')['QKS'].mean()
cvQKS.plot(kind='hist')
t = CountryQADF['QKS'][0.1]
conf_int = np.percentile((cvQKS), [90, 95, 99])
pValue = (cvQKS >= t).mean()

plt.show()
print('tₙ(τ):', CountryQADF['QKS'][0.1])
print('Confidence interval:',conf_int)
print('p-value:', pValue)

png

tₙ(τ): 2.681
Confidence interval: [2.7542  3.1293  3.74112]
p-value: 0.115

About

Quantile Augmented Dickey-Fuller unit root test

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages