def Get(self, name): if not self.Finance: return None if not JSComplierHelper.IsJsonNumber(self.Finance, name): return None value = self.Finance[name] return value
def RecvStockDayData(self, recvData, jobID): stocks = recvData['stock'] if not stocks or len(stocks) != 1: return aryStockDay = stocks[0]['stockday'] bFinanceData = False # 是否是定期的财务数据 bMarketValue = False # 是否计算市值 aryData = [] for item in aryStockDay: indexData = SingleData() indexData.Date = item['date'] if jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_CAPITAL_DATA: capitalData = item['capital'] if not capitalData or not JSComplierHelper.IsJsonNumber( capitalData, 'a'): continue indexData.Value = capitalData['a'] / 100 # 流通股本(手) bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_TOTAL_EQUITY_DATA: capitalData = item['capital'] if not capitalData or not JSComplierHelper.IsJsonNumber( capitalData, 'total'): continue indexData.Value = capitalData['total'] / 10000 #总股本(万股) bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_FLOW_EQUITY_DATA: capitalData = item['capital'] if not capitalData or not JSComplierHelper.IsJsonNumber( capitalData, 'a'): continue indexData.Value = capitalData['a'] / 10000 # 流通股本(万股) bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_FLOW_MARKETVALUE_DATA: #流通市值 capitalData = item['capital'] if not capitalData or not JSComplierHelper.IsJsonNumber( capitalData, 'a'): continue indexData.Value = capitalData['a'] # 流通股本 bMarketValue = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_MARKETVALUE_DATA: # 总市值 capitalData = item['capital'] if not capitalData or not JSComplierHelper.IsJsonNumber( capitalData, 'total'): continue indexData.Value = capitalData['total'] # 总股本 bMarketValue = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_EXCHANGE_DATA: # 换手率 capitalData = item['capital'] if not financeData or not JSComplierHelper.IsJsonNumber( capitalData, 'a'): continue indexData.Value = capitalData['a'] # 流通股本 bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_PER_U_PROFIT_DATA: if not self.GetFinanceValue(item, 'peruprofit', indexData): # 每股未分配利润 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_PER_NETASSET_DATA: if not self.GetFinanceValue(item, 'pernetasset', indexData): # 每股净资产 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_PER_C_RESERVE_DATA: if not self.GetFinanceValue(item, 'percreserve', indexData): # 每股资本公积金 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_PER_S_EARNING_DATA: if not self.GetFinanceValue(item, 'persearning', indexData): # 每股收益 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_PER_S_EARNING2_DATA: financeData = JSSymbolData.JsonDataToFinance(item) if not financeData or not financeData.Finance or not financeData.Announcement: continue if not JSComplierHelper.IsJsonNumber( financeData.Finance, 'persearning' ) or not JSComplierHelper.IsJsonDivideNumber( financeData.Announcement, 'quarter'): continue indexData.Value = financeData.Finance[ 'persearning'] / financeData.Announcement[ 'quarter'] * 4 # 每股收益(折算为全年收益) 报告期每股收益/报告期*4 bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_N_PROFIT_DATA: if not self.GetFinanceValue(item, 'nprofit', indexData): # 净利润 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_AL_RATIO_DATA: if not self.GetFinanceValue(item, 'alratio', indexData): # 资产负债率 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_PROFIT_YOY_DATA: if not self.GetFinanceValue(item, 'profityoy', indexData): # 净利润同比增长率 continue bFinanceData = True elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_DIVIDEND_YIELD_DATA: if not self.GetFinanceValue(item, 'quarter4', indexData): # 净利润同比增长率 continue else: continue aryData.append(indexData) if bFinanceData: aryFixedData = self.SourceData.GetFittingFinanceData(aryData) elif bMarketValue: aryFixedData = self.SourceData.GetFittingMarketValueData( aryData) # 总市值用不复权的价格计算 if jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_MARKETVALUE_DATA: self.MarketValue = aryFixedData # 总市值保存下 算其他数据可能要用 elif jobID == JS_EXECUTE_JOB_ID.JOB_DOWNLOAD_DIVIDEND_YIELD_DATA: # 股息率TTM:过去4个季度现金分红总额/总市值 * 100% aryFixedData = self.SourceData.CalculateDividendYield( aryData, self.MarketValue) else: aryFixedData = self.SourceData.GetFittingData(aryData) bindData = ChartData(data=aryFixedData) bindData.Period = self.Period if bindData.Period > 0: # 周期数据 periodData = bindData.GetPeriodSingleData(bindData.Period) bindData.Data = periodData data = bindData.GetValue() self.FinanceData[jobID] = data