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

     1  package factors
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/cache"
     5  	"gitee.com/quant1x/gox/logger"
     6  	"sync"
     7  )
     8  
     9  var (
    10  	__l5Once sync.Once
    11  	// 历史数据
    12  	__l5History *Cache1D[*History] = nil
    13  	// 基本面F10
    14  	__l5F10 *Cache1D[*F10] = nil
    15  	// 扩展交易特征
    16  	__l5Misc *Cache1D[*Misc] = nil
    17  	// 平台
    18  	__l5Box *Cache1D[*Box] = nil
    19  	// 情绪大师
    20  	__l5InvestmentSentimentMaster *Cache1D[*InvestmentSentimentMaster] = nil
    21  )
    22  
    23  func init() {
    24  	__l5Once.Do(lazyInitFeatures)
    25  }
    26  
    27  func lazyInitFeatures() {
    28  	// 历史数据
    29  	__l5History = NewCache1D[*History](cacheL5KeyHistory, NewHistory)
    30  	err := cache.Register(__l5History)
    31  	if err != nil {
    32  		logger.Fatalf("%+v", err)
    33  	}
    34  	// 基本面F10
    35  	__l5F10 = NewCache1D[*F10](cacheL5KeyF10, NewF10)
    36  	err = cache.Register(__l5F10)
    37  	if err != nil {
    38  		logger.Fatalf("%+v", err)
    39  	}
    40  	// 扩展信息
    41  	__l5Misc = NewCache1D[*Misc](cacheL5KeyMisc, NewMisc)
    42  	err = cache.Register(__l5Misc)
    43  	if err != nil {
    44  		logger.Fatalf("%+v", err)
    45  	}
    46  	// 平台
    47  	__l5Box = NewCache1D[*Box](cacheL5KeyBox, NewBox)
    48  	err = cache.Register(__l5Box)
    49  	if err != nil {
    50  		logger.Fatalf("%+v", err)
    51  	}
    52  	// 情绪大师
    53  	__l5InvestmentSentimentMaster = NewCache1D[*InvestmentSentimentMaster](cacheL5KeyInvestmentSentimentMaster, NewInvestmentSentimentMaster)
    54  	err = cache.Register(__l5InvestmentSentimentMaster)
    55  	if err != nil {
    56  		logger.Fatalf("%+v", err)
    57  	}
    58  }
    59  
    60  func GetL5History(securityCode string, date ...string) *History {
    61  	__l5Once.Do(lazyInitFeatures)
    62  	data := __l5History.Get(securityCode, date...)
    63  	if data == nil {
    64  		return nil
    65  	}
    66  	return *data
    67  }
    68  
    69  func GetL5F10(securityCode string, date ...string) *F10 {
    70  	__l5Once.Do(lazyInitFeatures)
    71  	data := __l5F10.Get(securityCode, date...)
    72  	if data == nil {
    73  		return nil
    74  	}
    75  	return *data
    76  }
    77  
    78  // GetL5Misc 获取扩展信息
    79  func GetL5Misc(securityCode string, date ...string) (exchange *Misc) {
    80  	__l5Once.Do(lazyInitFeatures)
    81  	v := __l5Misc.Get(securityCode, date...)
    82  	if v == nil {
    83  		return nil
    84  	}
    85  	return *v
    86  }
    87  
    88  // UpdateL5Misc 更新当日exchange
    89  func UpdateL5Misc(misc *Misc) {
    90  	__l5Once.Do(lazyInitFeatures)
    91  	__l5Misc.Set(misc.Code, misc, cache.DefaultCanReadDate())
    92  }
    93  
    94  // RefreshL5Misc 刷新缓存
    95  func RefreshL5Misc() {
    96  	__l5Once.Do(lazyInitFeatures)
    97  	__l5Misc.Apply(nil)
    98  }
    99  
   100  func FilterL5Misc(f func(v *Misc) bool, date ...string) []*Misc {
   101  	__l5Once.Do(lazyInitFeatures)
   102  	__l5Misc.Checkout(date...)
   103  	return __l5Misc.Filter(f)
   104  }
   105  
   106  // GetL5Box 获取平台数据
   107  func GetL5Box(securityCode string, date ...string) *Box {
   108  	__l5Once.Do(lazyInitFeatures)
   109  	v := __l5Box.Get(securityCode, date...)
   110  	if v == nil {
   111  		return nil
   112  	}
   113  	return *v
   114  }
   115  
   116  // GetL5InvestmentSentimentMaster 获取情绪大师的数据
   117  func GetL5InvestmentSentimentMaster(securityCode string, date ...string) (ism *InvestmentSentimentMaster) {
   118  	__l5Once.Do(lazyInitFeatures)
   119  	v := __l5InvestmentSentimentMaster.Get(securityCode, date...)
   120  	if v == nil {
   121  		return nil
   122  	}
   123  	return *v
   124  }