Created
June 24, 2017 04:54
-
-
Save nrm176/b4a3a0b1bb9f6d97c955e1e24cfd2912 to your computer and use it in GitHub Desktop.
Simple Moving Average
This file contains hidden or 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
import numpy as np | |
#mock data | |
data = '''853 1,005 | |
992 876 | |
589 1,330 | |
1,532 389 | |
1,414 508 | |
1,237 652 | |
''' | |
def simpleMovingAverage(values, window): | |
weights = np.repeat(1.0, window)/window | |
smas = np.convolve(values, weights, 'valid') | |
return smas | |
ups = [] | |
downs = [] | |
for d in data.split('\n'): | |
up, down = d.split('\t') | |
ups.append(int(up.replace(',', ''))) | |
downs.append(int(down.replace(',', ''))) | |
movingAverageUps = simpleMovingAverage(ups,6) | |
movingAverageDowns = simpleMovingAverage(downs,6) | |
for u,d in zip(movingAverageUps,movingAverageDowns): | |
print(np.round(u/d*100,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment