def calculateEMA(period, closeArray, emaArray=[]): length = len(closeArray)
nanCounter= np.count_nonzero(np.isnan(closeArray)) if not emaArray: emaArray.
extend(np.tile([np.nan], (nanCounter + period - 1))) firstema = np.mean(
closeArray[nanCounter:nanCounter + period - 1]) emaArray.append(firstema) for i
in range(nanCounter + period, length): ema = (2 * closeArray[i] + (period - 1) *
emaArray[-1]) / (period + 1) emaArray.append(ema) return np.array(emaArray) def
calculateMACD(closeArray, shortPeriod=12, longPeriod=26, signalPeriod=9): ema12
= calculateEMA(shortPeriod, closeArray, []) ema26 = calculateEMA(longPeriod,
closeArray, []) diff = ema12 - ema26 dea = calculateEMA(signalPeriod, diff, [])
macd= (diff - dea) fast_values = diff slow_values = dea diff_values = macd
return fast_values, slow_values, diff_values

技术
今日推荐
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信