gitee.com/quant1x/engine@v1.8.4/realtime/exponential_moving_average.go (about) 1 package realtime 2 3 import ( 4 "gitee.com/quant1x/engine/factors" 5 "gitee.com/quant1x/pandas/formula" 6 ) 7 8 // AlphaOfExponentialMovingAverage 计算EMA的alpha值 9 func AlphaOfExponentialMovingAverage(period int) float64 { 10 return formula.AlphaOfEMA(period) 11 } 12 13 // IncrementalExponentialMovingAverage 增量计算 指数移动平均线 14 func IncrementalExponentialMovingAverage(now, last, alpha float64) float64 { 15 return formula.EmaIncr(now, last, alpha) 16 } 17 18 // DynamicExponentialMovingAverage 动态EMA 19 // 20 // 返回当前值以及最高值和最低值 21 func DynamicExponentialMovingAverage(snapshot factors.QuoteSnapshot, last, alpha float64) (ema, emaHigh, emaLow float64) { 22 ema = IncrementalExponentialMovingAverage(snapshot.Price, last, alpha) 23 emaHigh = IncrementalExponentialMovingAverage(snapshot.High, last, alpha) 24 emaLow = IncrementalExponentialMovingAverage(snapshot.Low, last, alpha) 25 return 26 }