Note
Go to the end to download the full example code
ADFuller
Todo
Instead of calling the adf.from_list_dataframe
,
include an option in the grid_search
method to
return the result as a dataframe (to_dataframe).
The Augmented Dickey-Fuller test…
adf-statistic -9.4396
adf-pvalue 0.0
adf-nlags 0
adf-nobs 99
adf-stationary True
adf-criticalvalue_1% -4.0533
adf-criticalvalue_5% -3.4558
adf-criticalvalue_10% -3.1536
adf-x [100.12966...
adf-regression ct
adf-model (-9.439578...
adf-id ADF(ct)
dtype: object
Standard:
adfuller test stationarity (ct)
=======================================
statistic: -9.440
pvalue: 0.00000
nlags: 0
nobs: 99
stationarity (α=0.05): stationary
=======================================
Verbose:
adfuller test stationarity (ct)
=======================================
statistic: -9.440
pvalue: 0.00000
nlags: 0
nobs: 99
stationarity (α=0.05): stationary
---------------------------------------
critical value (1%): -4.05325
critical value (5%): -3.45581
critical value (10%): -3.15359
---------------------------------------
H0: Exists unit-root
H1: No Exists unit-root
pvalue <= α: Reject H0
=======================================
Identifier
ADF(ct)
1/3. ADF(c)
2/3. ADF(n)
3/3. ADF(ct)
0 1 2
adf-statistic -9.4921 0.0831 -9.4396
adf-pvalue 0.0 0.7112 0.0
adf-nlags 0 7 0
adf-nobs 99 92 99
adf-stationary True False True
adf-critica... -3.4982 -2.5905 -4.0533
adf-critica... -2.8912 -1.9443 -3.4558
adf-critica... -2.5826 -1.6142 -3.1536
adf-regression c n ct
adf-x [100.12966... [100.12966... [100.12966...
adf-model (-9.492118... (0.0830506... (-9.439578...
adf-id ADF(c) ADF(n) ADF(ct)
14 # Libraries
15 import numpy as np
16 import pandas as pd
17
18 # Import statsmodels
19 from statsmodels.tsa.stattools import adfuller
20
21 # Import pyAMR
22 from pyamr.core.stats.adfuller import ADFWrapper
23
24 # ----------------------------
25 # set basic configuration
26 # ----------------------------
27 # Set pandas configuration.
28 pd.set_option('display.max_colwidth', 14)
29 pd.set_option('display.width', 150)
30 pd.set_option('display.precision', 4)
31
32 # ----------------------------
33 # create data
34 # ----------------------------
35 # Constants
36 length = 100
37 offset = 100
38 slope = 10
39
40 # Create timeseries.
41 x = np.arange(length)
42 y = np.random.rand(length) * slope + offset
43
44 # ----------------------------
45 # create adfuller object
46 # ----------------------------
47 # Create object
48 adf = ADFWrapper(estimator=adfuller).fit(x=y, regression='ct')
49
50 # Print series.
51 print("\n")
52 print(adf.as_series())
53
54 # Print summary.
55 print("\n")
56 print("Standard:")
57 print(adf.as_summary())
58 print("\nVerbose:")
59 print(adf.as_summary(verbose=10))
60
61 # Print identifier.
62 print("\nIdentifier")
63 print(adf._identifier())
64
65 # -----------------
66 # Save and load
67 # -----------------
68 # File location
69 #fname = '../examples/saved/adfuller-sample.pickle'
70
71 # Save
72 #adf.save(fname=fname)
73
74 # Load
75 #adf = ADFWrapper().load(fname=fname)
76
77
78 # -----------
79 # Grid search
80 # -----------
81 # Create wrapper
82 adf = ADFWrapper(adfuller)
83
84 # Grid parameters.
85 grid_params = {'x': [y], 'regression': ['c','n','ct']}
86
87 # Get wrappers.
88 lwrappers = adf.grid_search(grid_params=grid_params, verbose=1)
89
90 # Get summary.
91 summary = adf.from_list_dataframe(lwrappers, flabel=True)
92
93 # Plot result.
94 print("\n")
95 print(summary.T)
Total running time of the script: ( 0 minutes 0.037 seconds)