def output(self): pro = ts.pro_api(token=TS_TOKEN) date = self._get_last_season_end(self.date) df = pro.fina_mainbz(ts_code=self.code, period=self.tushare_date_format(date), type='P') for i in range(5): # 最多尝试取6个季度的数据 if len(df) == 0: date = self._get_last_season_end(date) df = pro.fina_mainbz(ts_code=self.code, period=self.tushare_date_format(date), type='P') text = '\0\0' + self.code_name + '(' + self.code + ')的主营业务构成为(数据截止为' + date + '):\n' para_1 = rl_text(text) df = df.sort_values(by='bz_sales', axis=0, ascending=False) # 预处理,将None转化为np.nan df['bz_profit'] = pd.to_numeric(df['bz_profit']) df['bz_cost'] = pd.to_numeric(df['bz_cost']) # 计算辅助指标 df['bz_sales_ratio'] = df['bz_sales'] / np.sum( df['bz_sales'].fillna(0.0).values) # 计算营业收入占比 df['bz_profit_ratio'] = df['bz_profit'] / df['bz_sales'] # 计算毛利率 # 文字生成部分 table_list = [['业务名称', '销售收入', '销售成本', '销售毛利', '销售毛利率', '销售收入占比']] for i in range(len(df)): data = df.iloc[i].values table_list.append([ '%s' % data[2], '%.2f万元' % (data[3] / 10000.0), '%.2f万元' % (data[5] / 10000.0), '%.2f万元' % (data[4] / 10000.0), '%.2f%%' % (data[8] * 100.0), '%.2f%%' % (data[7] * 100.0) ]) table_1 = rl_table(table_list) # 总结内容 text = '\0\0' if len(df) > 0: summary_text = self._get_summary(df, self.code_name) text = text + summary_text else: # 无数据披露的情形 text = text + '无数据!\n' # 结果展示 para_2 = rl_text(text) # 饼图 texts = [] datas = [] for i in range(len(df)): data = df.iloc[i].values texts.append(data[2]) datas.append(data[7] * 100) title = self.code_name + '(' + self.code + ')的主营业务百分比构成图(数据截止为' + date + ')' image_1 = rl_pie_chart(title, datas, texts, str(random.randint(0, MAX_RANDOM))) return [para_1, table_1, rl_text('\0'), para_2, image_1, rl_text('\0')]
def output(self): from single_factor import RevenueGrowthRate, EstimateNetRevenueGrowRateFY16M factor_list = [RevenueGrowthRate, EstimateNetRevenueGrowRateFY16M] code = [self.code] df = get_factor_from_wind_v2(code, factor_list, self.date) df.iloc[:, 1] = pd.to_numeric(df.iloc[:, 1]) text = '\0\0营业收入分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '营业收入增长率为%.2f%%;分析师一致预期营业收入增长率为%.2f%%;' text = text % (df.iloc[:, 0].values, df.iloc[:, 1].values) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import OperateCashFlow, CashFlowCoverRatio factor_list = [OperateCashFlow, CashFlowCoverRatio] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df.iloc[:, 1] = pd.to_numeric(df.iloc[:, 1]) text = '\0\0现金流分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '经营活动现金流为%.2f亿元;' + '利润现金保障倍数为%.2f倍;' text = text % (df.iloc[:, 0].values/100000000.0, df.iloc[:, 1].values) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import InventoryTurnRatio factor_list = [InventoryTurnRatio] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) last_year = self._get_last_year_date(self.date) df_last_year = get_factor_from_wind_without_cache(code, factor_list, last_year) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values) / df_last_year.iloc[:, 0].values text = '\0\0存货周转率分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '存货周转率为%.2f次;上年同期为%.2f次;同比增长为%.2f%%。' text = text % (df.iloc[:, 0].values, df_last_year.iloc[:, 0], growth * 100.0) para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import SellExpense, SellExpenseRevenue, SellExpenseGrowth factor_list = [SellExpense, SellExpenseRevenue, SellExpenseGrowth] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df.iloc[:, 1] = pd.to_numeric(df.iloc[:, 1]) df.iloc[:, 2] = pd.to_numeric(df.iloc[:, 2]) text = '\0\0经营理念分析——销售费用(数据截止' + self.date + '):' para_1 = rl_text(text) text = '销售费用为为%.2f亿元;销售费用占营业收入的比重为:%.2f%%;销售费用增长率为%.2f%%;' text = text % (df.iloc[:, 0].values/100000000.0, df.iloc[:, 1].values * 100.0, df.iloc[:, 2].values * 100) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import NetProfit, NetProfitGrowRateV2, EstimateNetProfitGrowRateFY1_6M factor_list = [NetProfit, NetProfitGrowRateV2, EstimateNetProfitGrowRateFY1_6M] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df.iloc[:, 1] = pd.to_numeric(df.iloc[:, 1]) df.iloc[:, 2] = pd.to_numeric(df.iloc[:, 2]) text = '\0\0净利润增长分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '公司净利润为%.2f亿元;净利润增长率为%.2f%%;分析师一致预期净利润增长率为%.2f%%;' text = text % (df.iloc[:, 0].values/100000000.0, df.iloc[:, 1].values, df.iloc[:, 2].values) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import AccRecTurnRatioV2 factor_list = [AccRecTurnRatioV2] code = [self.code] date = self._get_last_year_end(self.date) df = get_factor_from_wind_without_cache(code, factor_list, date) date_last = self._get_last_year_date(date) df_last_year = get_factor_from_wind_without_cache(code, factor_list, date_last) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values) / df_last_year.iloc[:, 0].values text = '\0\0应收账款率分析(数据截止' + date + '):' para_1 = rl_text(text) text = '应收账款周转率为%.2f次;上年同期为%.2f次;同比增长为%.2f%%。' text = text % (df.iloc[:, 0].values, df_last_year.iloc[:, 0], growth * 100.0) para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import RDExpense, RDExpenseRevenue factor_list = [RDExpense, RDExpenseRevenue] code = [self.code] date = self._get_last_year_end(self.date) df = get_factor_from_wind_without_cache(code, factor_list, date) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df.iloc[:, 1] = pd.to_numeric(df.iloc[:, 1]) text = '\0\0经营理念分析——研发费用(数据截止' + date + '):' para_1 = rl_text(text) text = '研发费用为%.2f亿元:占营业收入为%.2f%%。' text = text % (df.iloc[:, 0].values / 100000000.0, df.iloc[:, 1].values * 100.0) para_2 = rl_text(text) if np.isnan(df.iloc[:, 0].values): return [] else: return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import ROE factor_list = [ROE] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) last_year = self._get_last_year_date(self.date) df_last_year = get_factor_from_wind_without_cache(code, factor_list, last_year) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values) / df_last_year.iloc[:, 0].values text = '\0\0业绩分析(资本回报率ROE)(数据截止' + self.date + '):' para_1 = rl_text(text) text = '资本回报为ROE%.2f%%;上年同期为%.2f%%;同比增长率为%.2f%%;' text = text % (df.iloc[:, 0].values, df_last_year.iloc[:, 0].values, growth * 100.0) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import AssetTurnoverRatio factor_list = [AssetTurnoverRatio] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) last_year = self._get_last_year_date(self.date) df_last_year = get_factor_from_wind_without_cache(code, factor_list, last_year) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values) / df_last_year.iloc[:, 0].values text = '\0\0管理层面分析_效率分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '总资产周转率本年为%.2f次;上年同期为%.2f次;同比增长率为%.2f%%;' text = text % (df.iloc[:, 0].values, df_last_year.iloc[:, 0], growth * 100.0) text_summary = self._get_summary(df, growth) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import NonCurrentAssetRatio factor_list = [NonCurrentAssetRatio] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) date_last = self._get_last_year_date(self.date) df_last_year = get_factor_from_wind_without_cache(code, factor_list, date_last) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values) / df_last_year.iloc[:, 0].values text = '\0\0资产结构分析(数据截止' + date + '):' para_1 = rl_text(text) text = '公司非流动资产占比为%.2f%%;上年同期为%.2f%%;同比增长为%.2f%%;' text = text % (df.iloc[:, 0].values, df_last_year.iloc[:, 0], growth * 100.0) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import DebetToAsset, TotalAsset factor_list = [DebetToAsset, TotalAsset] code = [self.code] df = get_factor_from_wind_without_cache(code, factor_list, self.date) last_year = self._get_last_year_date(self.date) df_last_year = get_factor_from_wind_without_cache(code, factor_list, last_year) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df.iloc[:, 1] = pd.to_numeric(df.iloc[:, 1]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values) / df_last_year.iloc[:, 0].values text = '\0\0管理层面分析_效率分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '总资产规模为%.2f亿元;资产负债率为%.2f%%;上年同期为%.2f%%;同比增长为%.2f%%;' text = text % (df.iloc[:, 1].values / 100000000.0, df.iloc[:, 0].values * 100.0, df_last_year.iloc[:, 0].values * 100.0, growth * 100.0) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]
def output(self): from single_factor import CurrentRatio factor_list = [CurrentRatio] code = [self.code] df = get_factor_from_wind_v2(code, factor_list, self.date) last_year = self._get_last_year_date(self.date) df_last_year = get_factor_from_wind_v2(code, factor_list, last_year) df.iloc[:, 0] = pd.to_numeric(df.iloc[:, 0]) df_last_year.iloc[:, 0] = pd.to_numeric(df_last_year.iloc[:, 0]) growth = (df.iloc[:, 0].values - df_last_year.iloc[:, 0].values ) / df_last_year.iloc[:, 0].values text = '\0\0短期偿债能力分析(数据截止' + self.date + '):' para_1 = rl_text(text) text = '流动比率为%.2f;上年同期为%.2f;同比增长率为%.2f%%;' text = text % (df.iloc[:, 0].values, df_last_year.iloc[:, 0].values, growth * 100.0) text_summary = self._get_summary(df) text = text + text_summary para_2 = rl_text(text) return [para_1, para_2, rl_text('\0')]