def factor_leverage(cur_date): # 现金比率,-1列为rank,-2列为所需要的 fa_cashtoliqdebt = om.get_fa_cashtoliqdebt(cur_date) # 流动比率,-1列为rank,-2列为所需要的 fa_current = om.get_fa_current(cur_date) # 权益乘数,-1列为rank,-2列为所需要的 fa_assetstoequity = om.get_fa_assetstoequity(cur_date) # 获取个股市值(带index) index_mkvalue = om.get_index_mkvalue(cur_date) cashration = fa_cashtoliqdebt.iloc[:, -2] # 现金比率 currentratio = fa_current.iloc[:, -2] # 流动比率 equitymultiplier = fa_assetstoequity.iloc[:, -2] ln_capital = np.log(index_mkvalue.iloc[:, -1]) # 市值对数 # 入库 stock_list = om.get_all_stock(cur_date) cashration_flag = fh.df_to_list(cur_date, cashration, 'cashration', stock_list) currentratio_flag = fh.df_to_list(cur_date, currentratio, 'currentratio', stock_list) equitymultiplier_flag = fh.df_to_list(cur_date, equitymultiplier, 'equitymultiplier', stock_list) ln_capital_flag = fh.df_to_list(cur_date, ln_capital, 'ln_capital', stock_list) if cashration_flag & currentratio_flag & equitymultiplier_flag & ln_capital_flag != 1: gl.logger.error('factor_leverage insert fail') return 0 else: gl.logger.info('factor_leverage insert successful') return 1
def factor_value(cur_date): # 获取EP(TTM),净利润/总市值(带index),(若净利润<=0,则返回空) inverse_ep = om.get_index_ep(cur_date) # 获取ps,市销率(PS,TTM) ps = om.get_ps(cur_date) # 获取pb值 也就是需要的bp,的倒数 inverse_bp = om.get_index_val_pb_new(cur_date) # 获取净现金流 val_pcf_ncfttm = om.get_index_val_pcf_ncfttm(cur_date) # 获取经营性现金流(ttm) val_pcf_ocfttm = om.get_index_val_pcf_ocfttm(cur_date) # 获取个股市值(带index) index_mkvalue = om.get_index_mkvalue(cur_date) ep = 1 / inverse_ep.iloc[:, -1] bp = 1 / inverse_bp.iloc[:, -1] sp = 1 / ps.iloc[:, -1] ncfp = val_pcf_ncfttm.iloc[:, -1] / index_mkvalue.iloc[:, -1] ocfp = val_pcf_ocfttm.iloc[:, -1] / index_mkvalue.iloc[:, -1] # 分红放在最后面了,主要是不是我写的 # 红利(近12个月股息率),首先拼接一年前的日期 struct_time = time.strptime(str(cur_date), '%Y%m%d') y = struct_time.tm_year - 1 m = struct_time.tm_mon d = struct_time.tm_mday year_before = str(date(y, m, d).replace(year=y)) year_before = year_before.replace('-', '') divdend = om.get_dps(year_before, str(cur_date)) divdend.index = divdend.iloc[:, 0] dp = divdend.iloc[:, -1] # 入库 stock_list = om.get_all_stock(cur_date) ep_flag = fh.df_to_list(cur_date, ep, 'ep', stock_list) bp_flag = fh.df_to_list(cur_date, bp, 'bp', stock_list) sp_flag = fh.df_to_list(cur_date, sp, 'sp', stock_list) ncfp_flag = fh.df_to_list(cur_date, ncfp, 'ncfp', stock_list) ocfp_flag = fh.df_to_list(cur_date, ocfp, 'ocfp', stock_list) dp_flag = fh.df_to_list(cur_date, dp, 'dp', stock_list) if ep_flag & bp_flag & sp_flag & ncfp_flag & ocfp_flag & dp_flag != 1: gl.logger.error('factor_value insert fail') return 0 else: gl.logger.info('factor_value insert successful') return 1