Skip to content

Instantly share code, notes, and snippets.

@alexrios22
Created November 22, 2020 22:00
Show Gist options
  • Save alexrios22/3ccc0e3ba38d0bb101a17b545eb3efcd to your computer and use it in GitHub Desktop.
Save alexrios22/3ccc0e3ba38d0bb101a17b545eb3efcd to your computer and use it in GitHub Desktop.
SeasonalDecompose.ibpynb
import statsmodels.api as sm
decomposition = sm.tsa.seasonal_decompose(data['Adj Close'], model="additive", period = 253)
trend = decomposition.trend
seasonal = decomposition.seasonal
residual = decomposition.resid
fig, axs = plt.subplots(4, figsize=(14, 10), sharex=True)
data['Adj Close'].plot(title='Original', color="blue", ax=axs[0])
trend.plot(title='Trend', color="red", ax=axs[1])
seasonal.plot(title='Seasonality', color="orange", ax=axs[2])
residual.plot(title='Residuals', color="green", ax=axs[3])
plt.tight_layout();seasonal["2019"].plot(label='Seasonality', color="blue", figsize=(20,8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment