1 Star 0 Fork 2

王布衣 / num

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
cross.go 852 Bytes
Copy Edit Raw Blame History
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/num.git
git@gitee.com:quant1x/num.git
quant1x
num
num
v0.3.2

Search

344bd9b3 5694891 D2dac590 5694891