Skip to content

Instantly share code, notes, and snippets.

@henryrossiter
Created February 4, 2020 23:17
Show Gist options
  • Save henryrossiter/6da6c5bea75590142ed17e99cb66ce36 to your computer and use it in GitHub Desktop.
Save henryrossiter/6da6c5bea75590142ed17e99cb66ce36 to your computer and use it in GitHub Desktop.
import numpy as np
def moving_average(a, n=3) :
ret = np.cumsum(a, dtype=float)
ret[n:] = ret[n:] - ret[:-n]
return ret[n - 1:] / n
n = 12
plt.plot(moving_average(btc_data, n=n))
plt.plot(btc_data[n - 1:])
plt.title('Daily Low Bitcoin Prices - 1 Year')
plt.legend(['{} day moving average of low prices'.format(n), 'daily low price'])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment