def generate(self, cdate, sh_df, sz_df, sh_rzrq_df, sz_rzrq_df, av_df, limit_info, stock_info, industry_info, index_info, all_stock_info, bull_ration_df): image_dir = os.path.join(self.sdir, "%s-StockReView" % cdate) file_name = "%s.md" % image_dir if os.path.exists(file_name): return True os.makedirs(image_dir, exist_ok=True) md = MarkdownWriter() md.addTitle(cdate) md.addHeader("股票复盘", 1) #指数行情 index_info = index_info[[ 'name', 'open', 'high', 'close', 'low', 'volume', 'amount', 'pchange' ]] md.addHeader("指数行情", 2) t_index = MarkdownTable( headers=["名称", "价格", "涨幅(百分比)", "成交量", "成交额(亿)"]) for index in range(len(index_info)): data_list = index_info.loc[index].tolist() data_list = [ data_list[0], round(data_list[3], 2), round(data_list[7], 2), int(data_list[5] / 100), round(data_list[6] / 100000000, 2) ] data_list = [str(i) for i in data_list] t_index.addRow(data_list) md.addTable(t_index) # 资金面分析 md.addHeader("资金面分析:", 2) x_dict = dict() x_dict['日期'] = sh_df.date.tolist() #上海和深圳的成交额分析 md.addHeader("成交额分析:", 3) self.market_plot(sh_df, sz_df, x_dict, 'amount', dir_name=image_dir) md.addImage("market_amount.png", imageTitle="成交额") #上海和深圳的流通市值分析 md.addHeader("流通市值分析:", 3) self.market_plot(sh_df, sz_df, x_dict, 'negotiable_value', dir_name=image_dir) md.addImage("market_negotiable_value.png", imageTitle="流通市值") #上海和深圳的换手率分析 md.addHeader("市场换手率分析:", 3) self.market_plot(sh_df, sz_df, x_dict, 'turnover', dir_name=image_dir) md.addImage("market_turnover.png", imageTitle="换手率") #上海和深圳的融资融券分析 md.addHeader("融资融券分析:", 3) y_dict = dict() y_dict['日期'] = sh_rzrq_df.date.tolist() self.market_plot(sh_rzrq_df, sz_rzrq_df, y_dict, 'rzrqye', dir_name=image_dir) md.addImage("market_rzrqye.png", imageTitle="融资融券") #平均股价走势 md.addHeader("平均股价分析:", 3) self.plot_ohlc(av_df, '平均股价', '平均股价走势图', image_dir, 'average_price') md.addImage("average_price.png", imageTitle="平均股价") #活点地图 md.addHeader("活点地图分析:", 3) mmap_clinet = MarauderMap() mmap_clinet.plot(cdate, image_dir, 'marauder_map') md.addImage("marauder_map.png", imageTitle="活点地图") #大盘是否超跌 md.addHeader("大盘是否超跌:", 3) moj = MarketOversoldJudger() md.addText("大盘是否超跌:%s" % moj.judge(stock_info)) #牛熊股比 md.addHeader("牛熊股比:", 3) self.plot_bullration(bull_ration_df, image_dir, 'bull_ration') md.addImage("bull_ration.png", imageTitle="牛熊股比") #涨停分析 md.addHeader("涨停跌停分析:", 3) self.static_plot(stock_info, limit_info, dir_name=image_dir, file_name='pchange_static') md.addImage("pchange_static.png", imageTitle="活点地图") #行业分析 md.addHeader("行业分析:", 2) ##总成交额分析 total_amount = industry_info['amount'].sum() df = industry_info.sort_values(by='amount', ascending=False) df = df[['name', 'code', 'amount']] df = df.head(min(9, len(df))) df.at[len(df)] = ['其他', '999999', total_amount - df['amount'].sum()] df['amount'] = df['amount'] / 1e8 xtuple = tuple( (df['name'] + ':' + df['amount'].astype('str') + '亿').tolist()) md.addHeader("总成交额分析:", 3) self.plot_pie(df, 'amount', '每日成交额行业分布', xtuple, image_dir, 'industry_amount_distribution', ctype='func') md.addImage("industry_amount_distribution.png", imageTitle="总成交额分析") ##总涨幅分析 df = industry_info[industry_info['pchange'] > 0] if not df.empty: df = df[['name', 'code', 'pchange']] df = df.sort_values(by='pchange', ascending=False) df = df.head(min(10, len(df))) xtuple = tuple((df['name'] + ':' + df['pchange'].astype('str') + '%').tolist()) md.addHeader("总涨幅分析:", 3) self.plot_pie(df, 'pchange', '每日涨幅行业分布', xtuple, image_dir, 'industry_price_increase_distribution') md.addImage("industry_price_increase_distribution.png", imageTitle="总涨幅分析") ##金额增加额的行业分布 df = industry_info[industry_info['money_change'] > 0] if not df.empty: df = df[['name', 'code', 'money_change']] df = df.sort_values(by='money_change', ascending=False) df = df.head(min(10, len(df))) xtuple = tuple((df['name'] + ':' + df['money_change'].astype('str') + '亿').tolist()) md.addHeader("金额增加额的行业分布:", 3) self.plot_pie(df, 'money_change', '每日成交增加额行业分布', xtuple, image_dir, 'industry_money_increase_distribution') md.addImage("industry_money_increase_distribution.png", imageTitle="金额增加额的行业分布") ##金额增加百分比的行业分布 df = industry_info[industry_info['mchange'] > 0] if not df.empty: df = df[['name', 'code', 'mchange']] df = df.sort_values(by='mchange', ascending=False) df = df.head(min(10, len(df))) xtuple = tuple((df['name'] + ':' + df['mchange'].astype('str') + '%').tolist()) md.addHeader("金额增加百分比的行业分布:", 3) self.plot_pie(df, 'mchange', '每日成交增加比例行业分布', xtuple, image_dir, 'industry_money_increase_percent_distribution') md.addImage("industry_money_increase_percent_distribution.png", imageTitle="金额增加百分比的行业分布") ##总跌幅分析 df = industry_info[industry_info['pchange'] < 0] if not df.empty: df = df[['name', 'code', 'pchange']] df = df.sort_values(by='pchange', ascending=True) df = df.head(min(10, len(df))) df['pchange'] = df['pchange'] * -1 xtuple = tuple((df['name'] + '跌幅:' + df['pchange'].astype('str') + '%').tolist()) md.addHeader("总跌幅分析:", 3) self.plot_pie(df, 'pchange', '每日涨幅行业分布', xtuple, image_dir, 'industry_price_decrease_distribution') md.addImage("industry_price_decrease_distribution.png", imageTitle="总跌幅分析") ##金额减少额的行业分布 df = industry_info[industry_info['money_change'] < 0] if not df.empty: df = df[['name', 'code', 'money_change']] df = df.sort_values(by='money_change', ascending=True) df = df.head(min(10, len(df))) df['money_change'] = df['money_change'] * -1 xtuple = tuple((df['name'] + ':减少' + df['money_change'].astype('str') + '亿').tolist()) md.addHeader("金额减少额的行业分布:", 3) self.plot_pie(df, 'money_change', '每日成交减少额行业分布', xtuple, image_dir, 'industry_money_decrease_distribution') md.addImage("industry_money_decrease_distribution.png", imageTitle="金额减少额的行业分布") ##金额减少百分比的行业分布 df = industry_info[industry_info['mchange'] < 0] if not df.empty: df = df[['name', 'code', 'mchange']] df = df.sort_values(by='mchange', ascending=False) df = df.head(min(10, len(df))) df['mchange'] = df['mchange'] * -1 xtuple = tuple((df['name'] + ':减少' + df['mchange'].astype('str') + '%').tolist()) md.addHeader("金额减少百分比的行业分布:", 3) self.plot_pie(df, 'mchange', '每日成交减少百分比行业分布', xtuple, image_dir, 'industry_money_decrease_percent_distribution') md.addImage("industry_money_decrease_percent_distribution.png", imageTitle="金额减少百分比的行业分布") #选股指标 md.addHeader("选股器选股", 2) t_selector = MarkdownTable(headers=["方法", "股票列表"]) stm = StrongerThanMarketSelecter() stm_code_list = stm.choose(all_stock_info, av_df) t_selector.addRow(['强于平均股价10%', json.dumps(stm_code_list)]) amus = AntiMarketUpSelecter() amus_code_list = amus.choose(stock_info) t_selector.addRow(['逆势上涨', json.dumps(amus_code_list)]) lvhps = LowVolumeHighProfitSelecter() lvhps_code_list = lvhps.choose(stock_info) t_selector.addRow(['高盈利低换手', json.dumps(lvhps_code_list)]) gkblvs = GameKLineBigraiseLargeVolumeSelecter() gkblvs_code_list = gkblvs.choose(stock_info) t_selector.addRow(['博弈K线带量长阳', json.dumps(gkblvs_code_list)]) gkbsvs = GameKLineBigraiseSmallVolumeSelecter() gkbsvs_code_list = gkbsvs.choose(stock_info) t_selector.addRow(['博弈K线无量长阳', json.dumps(gkbsvs_code_list)]) ncis = NeiChipIntensiveSelecter() ncis_code_list = ncis.choose(stock_info) t_selector.addRow(['低位筹码密集', json.dumps(ncis_code_list)]) bmbl = BullMoreBearLessSelecter() bmbl_code_list = bmbl.choose(all_stock_info) t_selector.addRow(['牛长熊短', json.dumps(bmbl_code_list)]) ncns = NoChipNetSpaceSelecter() ncns_code_list = ncns.choose(stock_info) t_selector.addRow(['无筹码净空间', json.dumps(ncns_code_list)]) md.addTable(t_selector) with open(file_name, "w+") as f: f.write(md.getStream())
index_info = get_index_data(end_date) #industry analysis industry_info = get_industry_data(cdate) #all stock info all_stock_info = RIndexStock().get_k_data_in_range(start_date, end_date) stm = StrongerThanMarketSelecter() stm_code_list = stm.choose(all_stock_info, av_df) amus = AntiMarketUpSelecter() amus_code_list = amus.choose(stock_info) lvhps = LowVolumeHighProfitSelecter() lvhps_code_list = lvhps.choose(stock_info) gkblvs = GameKLineBigraiseLargeVolumeSelecter() gkblvs_code_list = gkblvs.choose(stock_info) gkbsvs = GameKLineBigraiseSmallVolumeSelecter() gkbsvs_code_list = gkbsvs.choose(stock_info) ncis = NeiChipIntensiveSelecter() ncis_code_list = ncis.choose(stock_info) bmbl = BullMoreBearLessSelecter() bmbl_code_list = bmbl.choose(all_stock_info) ncns = NoChipNetSpaceSelecter() ncns_code_list = ncns.choose(stock_info) moj = MarketOversoldJudger()