def _ema(prices, days=10):
if len(prices) < days or days < 2: return [prices[-1]]
a = 2.0 / (days+1)
kernel = ones(days, dtype=float)
kernel[1:] = 1 - a
kernel = a * cumprod(kernel)
# The 0.8647 normalizes out that we stop the EMA after a finite number of terms
return convolve(prices[-days:], kernel, mode="valid") / (0.8647)
评论列表
文章目录