1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
last.go 685 Bytes
一键复制 编辑 原始数据 按行查看 历史
package formula
import (
"gitee.com/quant1x/pandas"
"gitee.com/quant1x/pandas/stat"
)
// LAST LAST(X,A,B):持续存在.
//
// A 支持序列化, B不支持
// 例如:
// LAST(CLOSE>OPEN,10,5)
// 表示从前10日到前5日内一直阳线
// 若A为0,表示从第一天开始,B为0,表示到最后日止
func LAST(X pandas.Series, A, B int) pandas.Series {
s := X.Rolling(A + 1).Apply(func(S pandas.Series, N stat.DType) stat.DType {
s := S.DTypes()
s = stat.Reverse(s)
T := s[B:]
n := len(T)
for _, v := range T {
if v != 0 {
n--
}
}
if n == 0 {
return 1
} else {
return 0
}
})
d := s.Values().([]stat.DType)
stat.Fill(d, 1, true)
return s
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.6.5

搜索帮助

344bd9b3 5694891 D2dac590 5694891