Created
August 6, 2019 17:40
-
-
Save marcopeix/2f6d69427f3d43e92958ae1bbab86287 to your computer and use it in GitHub Desktop.
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
def tsplot(y, lags=None, figsize=(12, 7), syle='bmh'): | |
if not isinstance(y, pd.Series): | |
y = pd.Series(y) | |
with plt.style.context(style='bmh'): | |
fig = plt.figure(figsize=figsize) | |
layout = (2,2) | |
ts_ax = plt.subplot2grid(layout, (0,0), colspan=2) | |
acf_ax = plt.subplot2grid(layout, (1,0)) | |
pacf_ax = plt.subplot2grid(layout, (1,1)) | |
y.plot(ax=ts_ax) | |
p_value = sm.tsa.stattools.adfuller(y)[1] | |
ts_ax.set_title('Time Series Analysis Plots\n Dickey-Fuller: p={0:.5f}'.format(p_value)) | |
smt.graphics.plot_acf(y, lags=lags, ax=acf_ax) | |
smt.graphics.plot_pacf(y, lags=lags, ax=pacf_ax) | |
plt.tight_layout() | |
tsplot(data.CLOSE, lags=30) | |
# Take the first difference to remove to make the process stationary | |
data_diff = data.CLOSE - data.CLOSE.shift(1) | |
tsplot(data_diff[1:], lags=30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment