1 Star 0 Fork 4

王布衣/ta-lib

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
ci.go 944 Bytes
Copy Edit Raw Blame History
王布衣 authored 2024-02-19 10:58 . 调整series函数
package sample
import (
"gitee.com/quant1x/num"
"gitee.com/quant1x/pandas"
. "gitee.com/quant1x/pandas/formula"
)
// ConfidenceInterval 置信区间(Confidence Interval, CI)
//
// df必须要用一个字段为N, 作为时间序列
func ConfidenceInterval(df pandas.DataFrame, argv ...int) pandas.DataFrame {
var (
LEN = df.Nrow()
CLOSE = df.ColAsNDArray("close")
HIGH = df.ColAsNDArray("high")
LOW = df.ColAsNDArray("low")
N = df.ColAsNDArray("N").DTypes()
CI = 0.9500 // 95%的置信区间
)
if len(argv) > 0 {
__n := argv[0]
N = num.Repeat[num.DType](num.DType(__n), LEN)
}
mid := MA(CLOSE, N)
variance := STD(CLOSE, N)
Z := num.ConfidenceIntervalToZscore(CI)
sd := variance.Mul(Z)
UP := mid.Add(sd)
LOWER := mid.Sub(sd)
B := LOW.Gt(LOWER).And(HIGH.Lt(UP))
df = pandas.NewDataFrame(df.Col("date"))
ob := pandas.NewSeriesWithType(pandas.SERIES_TYPE_BOOL, "cib", B)
df = df.Join(ob)
return df
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/ta-lib.git
git@gitee.com:quant1x/ta-lib.git
quant1x
ta-lib
ta-lib
v0.5.4

Search