2 Star 3 Fork 10

王布衣 / engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
feature_no1.go 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-01-11 11:15 . 适配exchange工具包
package factors
import (
"context"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/datasource/base"
"gitee.com/quant1x/engine/utils"
"gitee.com/quant1x/exchange"
"gitee.com/quant1x/gox/api"
"gitee.com/quant1x/pandas"
. "gitee.com/quant1x/pandas/formula"
)
type HousNo1 struct {
cache.DataSummary `dataframe:"-"`
MA5 float64 `dataframe:"ma5"`
MA10 float64 `dataframe:"ma10"`
MA20 float64 `dataframe:"ma20"`
}
func (this *HousNo1) GetDate() string {
//TODO implement me
panic("implement me")
}
func (this *HousNo1) GetSecurityCode() string {
//TODO implement me
panic("implement me")
}
func (this *HousNo1) Init(ctx context.Context, date string) error {
//TODO implement me
panic("implement me")
}
func (this *HousNo1) Factory(date string, code string) Feature {
//TODO implement me
panic("implement me")
}
func (this *HousNo1) FromHistory(history History) Feature {
no1 := history.Payloads.No1
_ = api.Copy(this, &no1)
return this
}
func (this *HousNo1) Update(code, cacheDate, featureDate string, complete bool) {
//TODO implement me
panic("implement me")
}
func (this *HousNo1) Repair(code, cacheDate, featureDate string, complete bool) {
securityCode := exchange.CorrectSecurityCode(code)
tradeDate := exchange.FixTradeDate(featureDate)
klines := base.CheckoutKLines(securityCode, tradeDate)
if len(klines) < cache.KLineMin {
return
}
df := pandas.LoadStructs(klines)
var (
//OPEN = df.ColAsNDArray("open")
CLOSE = df.ColAsNDArray("close")
//HIGH = df.ColAsNDArray("high")
//LOW = df.ColAsNDArray("low")
//VOL = df.ColAsNDArray("volume")
//AMOUNT = df.ColAsNDArray("amount")
)
offset := 1
if complete {
offset = 0
}
ma5 := MA(CLOSE, 5-offset)
this.MA5 = utils.SeriesIndexOf(ma5, -1)
ma10 := MA(CLOSE, 10-offset)
this.MA10 = utils.SeriesIndexOf(ma10, -1)
ma20 := MA(CLOSE, 20-offset)
this.MA20 = utils.SeriesIndexOf(ma20, -1)
_ = df
}
func (this *HousNo1) Increase(snapshot QuoteSnapshot) Feature {
tmp := HousNo1{}
tmp.MA5 = (this.MA5*4 + snapshot.Price) / 5
tmp.MA10 = (this.MA10*9 + snapshot.Price) / 10
tmp.MA20 = (this.MA20*19 + snapshot.Price) / 20
return &tmp
}
func (this *HousNo1) ValidateSample() error {
if this.MA20 > 0 {
return nil
}
return ErrInvalidFeatureSample
}
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v1.8.4

搜索帮助