January 2020
Beginner to intermediate
432 pages
11h 24m
English
Execute the following steps to test the given time series for stationarity.
import pandas as pdfrom statsmodels.graphics.tsaplots import plot_acf, plot_pacffrom statsmodels.tsa.stattools import adfuller, kpss
def adf_test(x): indices = ['Test Statistic', 'p-value', '# of Lags Used', '# of Observations Used'] adf_test = adfuller(x, autolag='AIC') results = pd.Series(adf_test[0:4], index=indices) for key, value in adf_test[4].items(): results[f'Critical Value ({key})'] = value return results
Now, we can run the test:
adf_test(df.price)
The code generates the following summary:
The null hypothesis of the ADF test states that the time series is not stationary. ...
Read now
Unlock full access