Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
3,230 additions
and
1,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Estimation and testing of cointegrated time series | ||
""" | ||
from __future__ import division | ||
|
||
import numpy as np | ||
|
||
from statsmodels.regression.linear_model import OLS | ||
from statsmodels.tools.tools import add_constant | ||
from statsmodels.tsa.unitroot import mackinnonp, mackinnoncrit | ||
|
||
|
||
def coint(y1, y2, regression="c"): | ||
""" | ||
This is a simple cointegration test. Uses unit-root test on residuals to | ||
test for cointegrated relationship | ||
See Hamilton (1994) 19.2 | ||
Parameters | ||
---------- | ||
y1 : array_like, 1d | ||
first element in cointegrating vector | ||
y2 : array_like | ||
remaining elements in cointegrating vector | ||
c : str {'c'} | ||
Included in regression | ||
* 'c' : Constant | ||
Returns | ||
------- | ||
coint_t : float | ||
t-statistic of unit-root test on residuals | ||
pvalue : float | ||
MacKinnon's approximate p-value based on MacKinnon (1994) | ||
crit_value : dict | ||
Critical values for the test statistic at the 1 %, 5 %, and 10 % | ||
levels. | ||
Notes | ||
----- | ||
The Null hypothesis is that there is no cointegration, the alternative | ||
hypothesis is that there is cointegrating relationship. If the pvalue is | ||
small, below a critical size, then we can reject the hypothesis that there | ||
is no cointegrating relationship. | ||
P-values are obtained through regression surface approximation from | ||
MacKinnon 1994. | ||
References | ||
---------- | ||
MacKinnon, J.G. 1994. "Approximate asymptotic distribution functions for | ||
unit-root and cointegration tests. `Journal of Business and Economic | ||
Statistics` 12, 167-76. | ||
""" | ||
regression = regression.lower() | ||
if regression not in ['c', 'nc', 'ct', 'ctt']: | ||
raise ValueError("regression option %s not understood") % regression | ||
y1 = np.asarray(y1) | ||
y2 = np.asarray(y2) | ||
if regression == 'c': | ||
y2 = add_constant(y2, prepend=False) | ||
st1_resid = OLS(y1, y2).fit().resid # stage one residuals | ||
lgresid_cons = add_constant(st1_resid[0:-1], prepend=False) | ||
uroot_reg = OLS(st1_resid[1:], lgresid_cons).fit() | ||
coint_t = (uroot_reg.params[0] - 1) / uroot_reg.bse[0] | ||
pvalue = mackinnonp(coint_t, regression="c", num_unit_roots=2) | ||
crit_value = mackinnoncrit(num_unit_roots=1, regression="c", nobs=len(y1)) | ||
return coint_t, pvalue, crit_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'kevin.sheppard' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Contains values used to approximate the critical value and | ||
p-value from DFGLS statistics | ||
These have been computed using the methodology of MacKinnon (1994) and (2010). | ||
simulation. | ||
""" | ||
|
||
from numpy import array | ||
|
||
dfgls_cv_approx = {'c': array([[-2.56781793e+00, -2.05575392e+01, 1.82727674e+02, | ||
-1.77866664e+03], | ||
[-1.94363325e+00, -2.17272746e+01, 2.60815068e+02, | ||
-2.26914916e+03], | ||
[-1.61998241e+00, -2.32734708e+01, 3.06474378e+02, | ||
-2.57483557e+03]]), | ||
'ct': array([[-3.40689134, -21.69971242, 27.26295939, -816.84404772], | ||
[-2.84677178, -19.69109364, 84.7664136, -799.40722401], | ||
[-2.55890707, -19.42621991, 116.53759752, -840.31342847]])} | ||
|
||
dfgls_tau_max = {'c': 13.365361509140614, | ||
'ct': 8.73743383728356} | ||
|
||
dfgls_tau_min = {'c': -17.561302895074206, | ||
'ct': -13.681153542634465} | ||
|
||
dfgls_tau_star = {'c': -0.4795076091714674, | ||
'ct': -2.1960404365401298} | ||
|
||
dfgls_large_p = {'c': array([0.50612497, 0.98305664, -0.05648525, 0.00140875]), | ||
'ct': array([2.60561421, 1.67850224, 0.0373599, -0.01017936])} | ||
|
||
dfgls_small_p = {'c': array([0.67422739, 1.25475826, 0.03572509]), | ||
'ct': array([2.38767685, 1.57454737, 0.05754439])} |
Oops, something went wrong.