gitee.com/quant1x/engine@v1.8.4/factors/feature_no1.go (about) 1 package factors 2 3 import ( 4 "context" 5 "gitee.com/quant1x/engine/cache" 6 "gitee.com/quant1x/engine/datasource/base" 7 "gitee.com/quant1x/engine/utils" 8 "gitee.com/quant1x/exchange" 9 "gitee.com/quant1x/gox/api" 10 "gitee.com/quant1x/pandas" 11 . "gitee.com/quant1x/pandas/formula" 12 ) 13 14 type HousNo1 struct { 15 cache.DataSummary `dataframe:"-"` 16 MA5 float64 `dataframe:"ma5"` 17 MA10 float64 `dataframe:"ma10"` 18 MA20 float64 `dataframe:"ma20"` 19 } 20 21 func (this *HousNo1) GetDate() string { 22 //TODO implement me 23 panic("implement me") 24 } 25 26 func (this *HousNo1) GetSecurityCode() string { 27 //TODO implement me 28 panic("implement me") 29 } 30 31 func (this *HousNo1) Init(ctx context.Context, date string) error { 32 //TODO implement me 33 panic("implement me") 34 } 35 36 func (this *HousNo1) Factory(date string, code string) Feature { 37 //TODO implement me 38 panic("implement me") 39 } 40 41 func (this *HousNo1) FromHistory(history History) Feature { 42 no1 := history.Payloads.No1 43 _ = api.Copy(this, &no1) 44 return this 45 } 46 47 func (this *HousNo1) Update(code, cacheDate, featureDate string, complete bool) { 48 //TODO implement me 49 panic("implement me") 50 } 51 52 func (this *HousNo1) Repair(code, cacheDate, featureDate string, complete bool) { 53 securityCode := exchange.CorrectSecurityCode(code) 54 tradeDate := exchange.FixTradeDate(featureDate) 55 klines := base.CheckoutKLines(securityCode, tradeDate) 56 if len(klines) < cache.KLineMin { 57 return 58 } 59 df := pandas.LoadStructs(klines) 60 var ( 61 //OPEN = df.ColAsNDArray("open") 62 CLOSE = df.ColAsNDArray("close") 63 //HIGH = df.ColAsNDArray("high") 64 //LOW = df.ColAsNDArray("low") 65 //VOL = df.ColAsNDArray("volume") 66 //AMOUNT = df.ColAsNDArray("amount") 67 ) 68 offset := 1 69 if complete { 70 offset = 0 71 } 72 ma5 := MA(CLOSE, 5-offset) 73 this.MA5 = utils.SeriesIndexOf(ma5, -1) 74 ma10 := MA(CLOSE, 10-offset) 75 this.MA10 = utils.SeriesIndexOf(ma10, -1) 76 ma20 := MA(CLOSE, 20-offset) 77 this.MA20 = utils.SeriesIndexOf(ma20, -1) 78 _ = df 79 } 80 81 func (this *HousNo1) Increase(snapshot QuoteSnapshot) Feature { 82 tmp := HousNo1{} 83 84 tmp.MA5 = (this.MA5*4 + snapshot.Price) / 5 85 tmp.MA10 = (this.MA10*9 + snapshot.Price) / 10 86 tmp.MA20 = (this.MA20*19 + snapshot.Price) / 20 87 return &tmp 88 } 89 90 func (this *HousNo1) ValidateSample() error { 91 if this.MA20 > 0 { 92 return nil 93 } 94 return ErrInvalidFeatureSample 95 }