diff --git a/formula/README.md b/formula/README.md index 63c49ab6f97f1647b079d4823f23175a2280c4a3..3334258db288b9d4b2c2314432122829c24ee6af 100644 --- a/formula/README.md +++ b/formula/README.md @@ -36,7 +36,7 @@ formula | 1 | EXIST | EXIST(CLOSE>O,5),最近N天是否都是True | EXIST(CLOSE>LOW,5) | [X] | [X] | | 1 | FILTER | FILTER函数,S满足条件后,将其后N周期内的数据置为0 | FILTER(CLOSE>LOW,5) | [X] | [X] | | 1 | BARSLAST | 上一次条件成立到当前的周期数 | BARSLAST(X) | [√] | [√] | -| 1 | BARSLASTCOUNT | 统计连续满足S条件的周期数 | BARSLASTCOUNT(X) | [X] | [X] | +| 1 | BARSLASTCOUNT | 统计连续满足S条件的周期数 | BARSLASTCOUNT(X) | [√] | [ ] | | 1 | BARSSINCEN | N周期内第一次S条件成立到现在的周期数 | BARSSINCEN(S,N) | [√] | [√] | | 1 | CROSS | 判断向上金叉穿越,两个序列互换就是判断向下死叉穿越 | CROSS(MA(C,5),MA(C,10)) | [X] | [X] | | 1 | LONGCROSS | 两条线维持一定周期后交叉,S1在N周期内都小于S2,本周期从S1下方向上穿过S2时返回1,否则返回0 | LONGCROSS(MA(C,5),MA(C,10),5) | [X] | [X] | diff --git a/formula/barslastcount.go b/formula/barslastcount.go new file mode 100644 index 0000000000000000000000000000000000000000..a34e4aaa2db92d2fa83fb59de664def38d0d9a0e --- /dev/null +++ b/formula/barslastcount.go @@ -0,0 +1,21 @@ +package formula + +import ( + "gitee.com/quant1x/pandas" + "gitee.com/quant1x/pandas/stat" +) + +// BARSLASTCOUNT 统计连续满足S条件的周期数 +func BARSLASTCOUNT(S pandas.Series) []int64 { + s := S.DTypes() + slen := len(s) + rt := stat.Repeat[int64](0, slen+1) + for i := 0; i < slen; i++ { + if s[i] != 0 { + rt[i+1] = rt[i] + 1 + } else { + rt[i+1] = rt[i+1] + } + } + return rt[1:] +} diff --git a/formula/barslastcount_test.go b/formula/barslastcount_test.go new file mode 100644 index 0000000000000000000000000000000000000000..3d1711d69ff1e4a2ac78dd6334f5b2d8c9ef9947 --- /dev/null +++ b/formula/barslastcount_test.go @@ -0,0 +1,14 @@ +package formula + +import ( + "fmt" + "gitee.com/quant1x/pandas" + "testing" +) + +func TestBARSLASTCOUNT(t *testing.T) { + f0 := []float64{1, 2, 3, 4, 5, 6, 0, 8, 9, 10, 11, 12} + i0 := CompareGte(f0, 1) + s0 := pandas.NewSeriesWithoutType("f0", i0) + fmt.Println(BARSLASTCOUNT(s0)) +} diff --git a/stat/zeros.go b/stat/zeros.go new file mode 100644 index 0000000000000000000000000000000000000000..acd2071f741b1af8b4b5a3d992096bcf6940922c --- /dev/null +++ b/stat/zeros.go @@ -0,0 +1,6 @@ +package stat + +// Zeros Return a new array of given shape and type, filled with zeros. +func Zeros() { + // 先占个坑 +}