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

     1  package factors
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/cache"
     5  	"gitee.com/quant1x/engine/datasource/dfcf"
     6  	"gitee.com/quant1x/exchange"
     7  	"gitee.com/quant1x/gox/api"
     8  	"gitee.com/quant1x/gox/logger"
     9  )
    10  
    11  var (
    12  	__mapQuarterlyReports = map[string]dfcf.QuarterlyReport{}
    13  )
    14  
    15  func loadQuarterlyReports(date string) {
    16  	var allReports []dfcf.QuarterlyReport
    17  	_, qEnd := api.GetQuarterDayByDate(date)
    18  	filename := cache.ReportsFilename(qEnd)
    19  	err := api.CsvToSlices(filename, &allReports)
    20  	if err != nil {
    21  		logger.Errorf("cache %s failed, error: %+v", filename, err)
    22  	}
    23  	if len(allReports) > 0 {
    24  		for _, v := range allReports {
    25  			__mapQuarterlyReports[v.SecurityCode] = v
    26  		}
    27  	}
    28  }
    29  
    30  func getQuarterlyYearQuarter(date string) string {
    31  	q, _, _ := api.GetQuarterByDate(date, 1)
    32  	return q
    33  }
    34  
    35  // 季报概要
    36  type quarterlyReportSummary struct {
    37  	QDate              string
    38  	BPS                float64
    39  	BasicEPS           float64
    40  	TotalOperateIncome float64
    41  	DeductBasicEPS     float64
    42  }
    43  
    44  func (q *quarterlyReportSummary) Assign(v dfcf.QuarterlyReport) {
    45  	q.BPS = v.BPS
    46  	q.BasicEPS = v.BasicEPS
    47  	q.TotalOperateIncome = v.TotalOperateIncome
    48  	q.DeductBasicEPS = v.DeductBasicEPS
    49  	q.QDate = v.QDATE
    50  }
    51  
    52  func getQuarterlyReportSummary(securityCode, date string) quarterlyReportSummary {
    53  	var summary quarterlyReportSummary
    54  	if exchange.AssertIndexBySecurityCode(securityCode) {
    55  		return summary
    56  	}
    57  	v, ok := __mapQuarterlyReports[securityCode]
    58  	if ok {
    59  		summary.Assign(v)
    60  		return summary
    61  	}
    62  	q := dfcf.GetCacheQuarterlyReportsBySecurityCode(securityCode, date)
    63  	if q != nil {
    64  		summary.Assign(*q)
    65  	}
    66  	return summary
    67  }