Skip to content

Instantly share code, notes, and snippets.

@marcopeix
Created August 6, 2019 17:27
Show Gist options
  • Save marcopeix/a9a37792661b57e581414735824e9e9d to your computer and use it in GitHub Desktop.
Save marcopeix/a9a37792661b57e581414735824e9e9d to your computer and use it in GitHub Desktop.
def exponential_smoothing(series, alpha):
result = [series[0]] # first value is same as series
for n in range(1, len(series)):
result.append(alpha * series[n] + (1 - alpha) * result[n-1])
return result
def plot_exponential_smoothing(series, alphas):
plt.figure(figsize=(17, 8))
for alpha in alphas:
plt.plot(exponential_smoothing(series, alpha), label="Alpha {}".format(alpha))
plt.plot(series.values, "c", label = "Actual")
plt.legend(loc="best")
plt.axis('tight')
plt.title("Exponential Smoothing")
plt.grid(True);
plot_exponential_smoothing(data.CLOSE, [0.05, 0.3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment