From 613af50ae045adb60d82a85bfcb4e777aef2747b Mon Sep 17 00:00:00 2001 From: wangfeng Date: Thu, 16 Feb 2023 20:07:54 +0800 Subject: [PATCH] =?UTF-8?q?#I6CYP5=20=E5=AE=9E=E7=8E=B0=E9=80=9A=E8=BE=BE?= =?UTF-8?q?=E4=BF=A1HHVBARS=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formula/hhvbars.go | 16 ++++++++++++++++ formula/hhvbars_test.go | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 formula/hhvbars.go create mode 100644 formula/hhvbars_test.go diff --git a/formula/hhvbars.go b/formula/hhvbars.go new file mode 100644 index 0000000..c27f4fa --- /dev/null +++ b/formula/hhvbars.go @@ -0,0 +1,16 @@ +package formula + +import "gitee.com/quant1x/pandas/stat" + +// HHVBARS 求上一高点到当前的周期数. +// +// 用法: +// HHVBARS(X,N):求N周期内X最高值到当前周期数,N=0表示从第一个有效值开始统计 +// 例如: +// HHVBARS(HIGH,0)求得历史新高到到当前的周期数 +func HHVBARS(S stat.Series, N any) stat.Series { + x := S.Rolling(N).Apply(func(X stat.Series, W stat.DType) stat.DType { + return stat.Any2DType(X.Reverse().ArgMax()) + }) + return x +} diff --git a/formula/hhvbars_test.go b/formula/hhvbars_test.go new file mode 100644 index 0000000..9d949d8 --- /dev/null +++ b/formula/hhvbars_test.go @@ -0,0 +1,13 @@ +package formula + +import ( + "fmt" + "gitee.com/quant1x/pandas/stat" + "testing" +) + +func TestHHVBARS(t *testing.T) { + n1 := []float32{1.1, 2.2, 1.3, 1.4} + s1 := stat.NewSeries[float32](n1...) + fmt.Println(HHVBARS(s1, 2)) +} -- Gitee