gitee.com/quant1x/engine@v1.8.4/factors/feature_box.go (about)

     1  package factors
     2  
     3  import (
     4  	"context"
     5  	"gitee.com/quant1x/engine/cache"
     6  	"gitee.com/quant1x/gox/logger"
     7  )
     8  
     9  const (
    10  	cacheL5KeyBox = "box"
    11  )
    12  
    13  // Box 平台特征数据
    14  type Box struct {
    15  	cache.DataSummary `dataframe:"-"`
    16  	Code              string  `name:"证券代码" dataframe:"证券代码"`                 // 证券代码
    17  	Date              string  `name:"数据日期" dataframe:"数据日期"`                 // 数据日期
    18  	DoubletPeriod     int     `name:"倍量周期" dataframe:"倍量周期"`                 // 倍量周期
    19  	DoubleHigh        float64 `name:"倍量最高" dataframe:"倍量最高"`                 // 倍量最高
    20  	DoubleLow         float64 `name:"倍量最低" dataframe:"倍量最低"`                 // 倍量最低
    21  	Buy               bool    `name:"买入信号" dataframe:"买入信号"`                 // 买入信号
    22  	HalfPeriod        int     `name:"半量周期" dataframe:"半量周期"`                 // 半量周期
    23  	HalfHigh          float64 `name:"半量最高" dataframe:"半量最高"`                 // 半量最高
    24  	HalfLow           float64 `name:"半量最低" dataframe:"半量最低"`                 // 半量最低
    25  	Sell              bool    `name:"卖出信号" dataframe:"卖出信号"`                 // 卖出信号
    26  	TendencyPeriod    int     `name:"趋势周期" dataframe:"趋势周期"`                 // 趋势周期
    27  	QSFZ              bool    `name:"QSFZ" dataframe:"QSFZ"`                 // QSFZ
    28  	QSCP              float64 `name:"QSCP" dataframe:"QSCP"`                 // QSFZ: QSCP
    29  	QSCV              float64 `name:"QSCV" dataframe:"QSCV"`                 // QSFZ: QSCV
    30  	QSVP              float64 `name:"QSVP" dataframe:"QSVP"`                 // QSFZ: QSVP
    31  	QSVP3             float64 `name:"QSVP3" dataframe:"QSVP3"`               // QSFZ: QSVP3
    32  	QSVP5             float64 `name:"QSVP5" dataframe:"QSVP5"`               // QSFZ: QSVP5
    33  	DkCol             float64 `name:"DkCol" dataframe:"DkCol"`               // dkqs: 能量柱
    34  	DkD               float64 `name:"dkd" dataframe:"dkd"`                   // dkqs: 多头力量
    35  	DkK               float64 `name:"dkk" dataframe:"dkk"`                   // dkqs: 空头力量
    36  	DkB               bool    `name:"dkb" dataframe:"dkb"`                   // dkqs: buy
    37  	DkS               bool    `name:"dks" dataframe:"dks"`                   // dkqs: sell
    38  	DxDivergence      float64 `name:"dxdivergence" dataframe:"dxdivergence"` // madx: 综合发散度评估值
    39  	DxDm0             float64 `name:"dxdm0" dataframe:"dxdm0"`               // madx: 超短线均线发散度
    40  	DxDm1             float64 `name:"dxdm1" dataframe:"dxdm1"`               // madx: 短线均线发散度
    41  	DxDm2             float64 `name:"dxdm2" dataframe:"dxdm2"`               // madx: 中线均线发散度
    42  	DxB               bool    `name:"dxb" dataframe:"dxb"`                   // madx: 买入
    43  	State             uint64  `name:"样本状态" dataframe:"样本状态"`                 // 样本状态
    44  }
    45  
    46  func NewBox(date, code string) *Box {
    47  	summary := __mapFeatures[FeatureBreaksThroughBox]
    48  	v := Box{
    49  		DataSummary: summary,
    50  		Date:        date,
    51  		Code:        code,
    52  	}
    53  	return &v
    54  }
    55  
    56  func (this *Box) GetDate() string {
    57  	return this.Date
    58  }
    59  
    60  func (this *Box) GetSecurityCode() string {
    61  	return this.Code
    62  }
    63  
    64  func (this *Box) Factory(date string, code string) Feature {
    65  	v := NewBox(date, code)
    66  	return v
    67  }
    68  
    69  func (this *Box) Init(ctx context.Context, date string) error {
    70  	_ = ctx
    71  	_ = date
    72  	return nil
    73  }
    74  
    75  func (this *Box) FromHistory(history History) Feature {
    76  	_ = history
    77  	return this
    78  }
    79  
    80  func (this *Box) Update(code, cacheDate, featureDate string, complete bool) {
    81  	cover := NewKLineBox(code, featureDate)
    82  	if cover == nil {
    83  		logger.Errorf("code[%s, %s] kline not found", code, featureDate)
    84  		return
    85  	}
    86  	info := this
    87  	info.Date = cover.Date
    88  	info.DoubletPeriod = cover.DoubletPeriod
    89  	info.DoubleHigh = cover.DoubleHigh
    90  	info.DoubleLow = cover.DoubleLow
    91  	info.Buy = cover.Buy
    92  	info.HalfPeriod = cover.HalfPeriod
    93  	info.HalfHigh = cover.HalfHigh
    94  	info.HalfLow = cover.HalfLow
    95  	info.Sell = cover.Sell
    96  	info.TendencyPeriod = cover.TendencyPeriod
    97  
    98  	// 趋势反转
    99  	info.QSFZ = cover.QSFZ
   100  	info.QSCP = cover.QSCP
   101  	info.QSCV = cover.QSCV
   102  	info.QSVP = cover.QSVP
   103  	info.QSVP3 = cover.QSVP3
   104  	info.QSVP5 = cover.QSVP5
   105  
   106  	// 多空趋势
   107  	info.DkCol = cover.DkCol
   108  	info.DkD = cover.DkD
   109  	info.DkK = cover.DkK
   110  	info.DkB = cover.DkB
   111  	info.DkS = cover.DkS
   112  
   113  	// 均线发散
   114  	info.DxDm0 = cover.DxDm0
   115  	info.DxDm1 = cover.DxDm1
   116  	info.DxDm2 = cover.DxDm2
   117  	info.DxDivergence = cover.DxDivergence
   118  	info.DxB = cover.DxB
   119  
   120  	// 样本状态
   121  	info.State |= cover.Kind()
   122  	_ = cacheDate
   123  	_ = complete
   124  }
   125  
   126  func (this *Box) Repair(code, cacheDate, featureDate string, complete bool) {
   127  	this.Update(code, cacheDate, featureDate, complete)
   128  }
   129  
   130  func (this *Box) Increase(snapshot QuoteSnapshot) Feature {
   131  	_ = snapshot
   132  	return this
   133  }
   134  
   135  // ValidateSample 验证样本数据
   136  func (this *Box) ValidateSample() error {
   137  	if this.State > 0 {
   138  		return nil
   139  	}
   140  	return ErrInvalidFeatureSample
   141  }