1 Star 0 Fork 1

王布衣 / num

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cross.go 852 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-03-11 08:56 . 修复趋势检测的条件错误的bug
package num
// 趋势变化
const (
Unchanged = 0 // 趋势不变
BreakThrough = 1 // break through 突破
FallDrastically = -1 // fall drastically 跌破
)
// LinerTrend 线性趋势
type LinerTrend struct {
X int // 索引
State int // 状态
}
// Cross 上穿和下穿
//
// a 上穿或者下穿b的状态集合
func Cross[E Number](a, b []E) []LinerTrend {
length := len(a)
list := make([]LinerTrend, length)
count := 0
for i := 1; i < length; i++ {
front := i - 1
current := i
if a[front] < b[front] && a[current] > b[current] {
// a 上穿 b
list[count] = LinerTrend{X: current, State: BreakThrough}
count++
} else if a[front] > b[front] && a[current] < b[current] {
// a 下穿 b
list[count] = LinerTrend{X: current, State: FallDrastically}
count++
}
}
list = list[:count]
return list
}
Go
1
https://gitee.com/quant1x/num.git
git@gitee.com:quant1x/num.git
quant1x
num
num
v0.3.1

搜索帮助