Files
gostock/internal/logic/strategy/rule/utils.go

36 lines
741 B
Go
Raw Normal View History

2026-01-30 01:12:21 +08:00
package rule
// 如果数据是降序(最新在前),需要反转
func reverseSlice(s []float64) []float64 {
result := make([]float64, len(s))
for i, j := 0, len(s)-1; i < len(s); i, j = i+1, j-1 {
result[i] = s[j]
}
return result
}
// 检查值是否为数组最后N个元素中的最小值
func CheckLowest(prices []float64, target int, n int) bool {
if len(prices) == 0 || n <= 0 {
return false
}
// 如果n大于数组长度使用整个数组
if n > len(prices) {
n = len(prices)
}
// 获取最后n个元素
slice := prices[len(prices)-n:]
// 查找最小值
minVal := slice[0]
for _, val := range slice[1:] {
if val < minVal {
minVal = val
}
}
return target == int(minVal)
}