bashtage / arch

ARCH models in Python
Other
1.34k stars 248 forks source link

PhillipsPerron rho test __str__() fails #385

Closed michaelkjohnston closed 4 years ago

michaelkjohnston commented 4 years ago

Here's an example setup that will reproduce it.

import arch.data.default

default_data = arch.data.default.load()
default = default_data.BAA.copy()

from arch.unitroot import PhillipsPerron

The tau version works:


y = PhillipsPerron(default, trend='n', test_type='tau')

y.__str__()
Out[54]: '     Phillips-Perron Test (Z-tau)    \n=====================================\nTest Statistic                 -1.951\nP-value                         0.049\nLags                               23\n-------------------------------------\n\nTrend: No Trend\nCritical Values: -2.57 (1%), -1.94 (5%), -1.62 (10%)\nNull Hypothesis: The process contains a unit root.\nAlternative Hypothesis: The process is weakly stationary.'

The rho version doesn't:

y = PhillipsPerron(default, trend='n', test_type='rho')

y.__str__()
Traceback (most recent call last):

  File "<ipython-input-56-8cc462d9ab10>", line 1, in <module>
    y.__str__()

  File "C:\Users\u609587\AppData\Local\Continuum\anaconda3\lib\site-packages\arch\unitroot\unitroot.py", line 484, in __str__
    return self.summary().__str__()

  File "C:\Users\u609587\AppData\Local\Continuum\anaconda3\lib\site-packages\arch\unitroot\unitroot.py", line 570, in summary
    ("Test Statistic", "{0:0.3f}".format(self.stat)),

  File "C:\Users\u609587\AppData\Local\Continuum\anaconda3\lib\site-packages\arch\unitroot\unitroot.py", line 554, in stat
    self._compute_if_needed()

  File "C:\Users\u609587\AppData\Local\Continuum\anaconda3\lib\site-packages\arch\unitroot\unitroot.py", line 517, in _compute_if_needed
    self._compute_statistic()

  File "C:\Users\u609587\AppData\Local\Continuum\anaconda3\lib\site-packages\arch\unitroot\unitroot.py", line 1171, in _compute_statistic
    self._pvalue = mackinnonp(self._stat, regression=trend, dist_type=dist_type)

  File "C:\Users\u609587\AppData\Local\Continuum\anaconda3\lib\site-packages\arch\unitroot\unitroot.py", line 1815, in mackinnonp
    maxstat = adf_z_max[regression]

KeyError: 'n'
bashtage commented 4 years ago

Definitely a bug. I need to redo that Z test critical values that were talked from statsmodels but I cannot even match these to the original paper.

bashtage commented 4 years ago

Thanks for reporting.

michaelkjohnston commented 4 years ago

Thank you!!