Skip to content

Instantly share code, notes, and snippets.

@kperry2215
Created July 20, 2019 02:49
Show Gist options
  • Save kperry2215/4be4261fedefe896ee382cb47e203930 to your computer and use it in GitHub Desktop.
Save kperry2215/4be4261fedefe896ee382cb47e203930 to your computer and use it in GitHub Desktop.
def augmented_dickey_fuller_statistics(time_series):
"""
Run the augmented Dickey-Fuller test on a time series
to determine if it's stationary.
Arguments:
time_series: series. Time series that we want to test
Outputs:
Test statistics for the Augmented Dickey Fuller test in
the console
"""
result = adfuller(time_series.values)
print('ADF Statistic: %f' % result[0])
print('p-value: %f' % result[1])
print('Critical Values:')
for key, value in result[4].items():
print('\t%s: %.3f' % (key, value))
#Execute in the main block
#Run each transformed, differenced time series thru the Augmented Dickey Fuller test
print('Augmented Dickey-Fuller Test: Electricity Price Time Series')
augmented_dickey_fuller_statistics(master_df['Electricity_Price_Transformed_Differenced'].dropna())
print('Augmented Dickey-Fuller Test: Natural Gas Price Time Series')
augmented_dickey_fuller_statistics(master_df['Nat_Gas_Price_MCF_Transformed_Differenced'].dropna())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment