2 Star 15 Fork 17

王布衣/engine

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
movingaverage.go 830 Bytes
Copy Edit Raw Blame History
王布衣 authored 2023-12-14 13:17 +08:00 . 增加增量计算均线的函数
package realtime
import (
"gitee.com/quant1x/gox/num"
"gitee.com/quant1x/pandas/formula"
"gitee.com/quant1x/pandas/stat"
)
// MovingAverage 计算均线范围
func MovingAverage(CLOSE, HIGH, LOW stat.Series, PN int) (ma, half, maMax, maMin stat.Series) {
half = formula.MA(CLOSE, PN-1)
r1Half := formula.REF(half, 1)
maMax = r1Half.Mul(PN - 1).Add(HIGH).Div(PN)
maMin = r1Half.Mul(PN - 1).Add(LOW).Div(PN)
ma = r1Half.Mul(PN - 1).Add(CLOSE).Div(PN)
return ma, half, maMax, maMin
}
// IncrementalMovingAverage 增量计算移动平均线
//
// period 周期数
// previousHalfValue 前period-1的平均值
// price 现价
func IncrementalMovingAverage(previousHalfValue float64, period int, price float64) float64 {
n := float64(period)
sum := previousHalfValue*(n-1) + price
ma := num.Decimal(sum / n)
return ma
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.8.7

Search