From 6f9f01d0b969dce35fe242fbd1e5603171b60a5c Mon Sep 17 00:00:00 2001 From: wangfeng Date: Thu, 9 Feb 2023 17:31:30 +0800 Subject: [PATCH] =?UTF-8?q?#I6E1HG=20=E5=AE=9E=E7=8E=B0BARSLASTCOUNT?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formula/README.md | 2 +- formula/barslastcount.go | 21 +++++++++++++++++++++ formula/barslastcount_test.go | 14 ++++++++++++++ stat/zeros.go | 6 ++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 formula/barslastcount.go create mode 100644 formula/barslastcount_test.go create mode 100644 stat/zeros.go diff --git a/formula/README.md b/formula/README.md index 63c49ab..3334258 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 0000000..a34e4aa --- /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 0000000..3d1711d --- /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 0000000..acd2071 --- /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() { + // 先占个坑 +} -- Gitee