def movingaverage (values, window): weights = np.repeat(1.0, window)/window sma = np.convolve(values, weights, 'valid') return sma