gitee.com/quant1x/engine@v1.8.4/strategies/no1.go (about) 1 package strategies 2 3 import ( 4 "gitee.com/quant1x/engine/config" 5 "gitee.com/quant1x/engine/factors" 6 "gitee.com/quant1x/engine/models" 7 "gitee.com/quant1x/engine/utils" 8 "gitee.com/quant1x/gotdx/securities" 9 "gitee.com/quant1x/gox/concurrent" 10 "gitee.com/quant1x/gox/logger" 11 "gitee.com/quant1x/pandas" 12 . "gitee.com/quant1x/pandas/formula" 13 ) 14 15 const ( 16 // MaximumResultDays 结果最大天数 17 MaximumResultDays int = 3 18 ) 19 20 func init() { 21 err := models.Register(ModelNo1{}) 22 if err != nil { 23 logger.Fatalf("%+v", err) 24 } 25 } 26 27 // ModelNo1 1号模型 28 // 29 // FormulaNo1 3天内5天线上穿10天线,10天线上穿20天线的个股 30 // count(cross(MA(c,5),MA(c,10)),3)>=1 and count(cross(MA(c,10),MA(c,20)),3)>=1 31 type ModelNo1 struct { 32 } 33 34 func (m ModelNo1) Code() models.ModelKind { 35 return models.ModelHousNo1 36 } 37 38 func (m ModelNo1) Name() string { 39 return models.MapStrategies[m.Code()].Name 40 } 41 42 func (m ModelNo1) OrderFlag() string { 43 return models.OrderFlagTail 44 } 45 46 func (m ModelNo1) Filter(ruleParameter config.RuleParameter, snapshot factors.QuoteSnapshot) error { 47 return GeneralFilter(ruleParameter, snapshot) 48 } 49 50 func (m ModelNo1) Sort(snapshots []factors.QuoteSnapshot) models.SortedStatus { 51 _ = snapshots 52 return models.SortDefault 53 } 54 55 func (m ModelNo1) Evaluate(securityCode string, result *concurrent.TreeMap[string, models.ResultInfo]) { 56 history := factors.GetL5History(securityCode) 57 if history == nil { 58 return 59 } 60 snapshot := models.GetStrategySnapshot(securityCode) 61 if snapshot == nil { 62 return 63 } 64 65 // 取出昨日的数据 66 lastNo1 := history.Last.No1 67 r1MA5 := lastNo1.MA5 68 r1MA10 := lastNo1.MA10 69 r1MA20 := lastNo1.MA20 70 // 取出今日的半成品数据 71 today := history.Payloads.No1.Increase(*snapshot).(*factors.HousNo1) 72 ma5 := today.MA5 73 ma10 := today.MA10 74 ma20 := today.MA20 75 76 // 组织series 77 s5 := pandas.ToSeries(r1MA5, ma5) 78 s10 := pandas.ToSeries(r1MA10, ma10) 79 s20 := pandas.ToSeries(r1MA20, ma20) 80 81 // 两个金叉 82 c1 := CROSS(s5, s10) 83 c2 := CROSS(s10, s20) 84 // 横向对比 85 d := c1.And(c2) 86 s := utils.BoolIndexOf(d, -1) 87 if s { 88 price := snapshot.Price 89 date := snapshot.Date 90 result.Put(securityCode, models.ResultInfo{Code: securityCode, 91 Name: securities.GetStockName(securityCode), 92 Date: date, 93 Rate: 0.00, 94 Buy: price, 95 Sell: price * 1.05, 96 StrategyCode: m.Code(), 97 StrategyName: m.Name()}) 98 } 99 }