1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
filter.go 931 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-02-18 15:26 . !68修订部分问题, 清理package
package formula
import (
"gitee.com/quant1x/pandas/stat"
"github.com/mymmsc/gox/exception"
)
// FILTER 过滤连续出现的信号
//
// 用法:
// FILTER(X,N):X满足条件后,将其后N周期内的数据置为0,N为常量.
// 例如:
// FILTER(CLOSE>OPEN,5)查找阳线,5天内再次出现的阳线不被记录在内
func FILTER(S stat.Series, N any) stat.Series {
var W []stat.DType
switch v := N.(type) {
case int:
W = stat.Repeat[stat.DType](stat.DType(v), S.Len())
case stat.Series:
vs := v.DTypes()
W = stat.Align(vs, stat.DTypeNaN, S.Len())
default:
panic(exception.New(1, "error window"))
}
length := S.Len()
x := S.DTypes()
for i := 0; i < length; i++ {
if x[i] != 0 {
start := i + 1
if start >= length {
continue
}
end := i + 1 + int(W[i])
if end >= length {
end = length
}
for j := start; j < end; j++ {
x[j] = 0
}
}
}
return stat.NDArray[stat.DType](x)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.9.11

搜索帮助

344bd9b3 5694891 D2dac590 5694891