def financial_factors_rank(path_root, filename='rank_result', dates=['2018-09-30'], factors=[FID['roe'], FID['roa']]): path = os.path.join(path_root) path_score = os.path.join(path_root, 'score') path_rank = os.path.join(path_root, 'rank') path_factor = os.path.join(path_root, 'factor_io') scu = SCU(path=path_root) stocks = scu.stock_codes_remove_no_stock_basic() ffr = financial_factor_rank(path=path, path_factor=path_factor, path_cluster=path_rank, stocks=stocks, dates=dates, indexs=factors, file_name=filename) """ FID['debt_incr_rate'],\ ###asset struct FID['debt_asset_ratio'],\ FID['debt_equality_ratio'],\ FID['debt_net_asset_ratio'],\ FID['revenue_asset_ratio'],\ FID['goodwell_equality_ratio'],\ FID['dev_rev_ratio']\ """ ffr.assess_selected_financial_factor(dates) print('rank all the stock successfully')
def processed_all_stocks_basic(path_root='../../../data/'): scu = SCU(path_root) stock_codes = scu.stock_codes_remove_no_stock_basic() proc_dr = DR(path_root, 'stock_basic_proc.json') proc_id = proc_dr.read_index() if (proc_id >= len(stock_codes)): print("finished to proc all the stock, number is ", len(stock_codes)) else: stock_codes = stock_codes[proc_id:] sb = stock_basic(stock_codes, path_root) sb.processed_stocks_basic() print('processed successfully')
def main_financial_data_process(path): scu = SCU(path=path) stock_codes = scu.stock_codes_remove_no_stock_basic() FFC = financail_factor_calc(path=path) dr = DR(path, 'stock_finance_factor_calc.json') #stock_codes = ['000001'] proc_id = dr.read_index() stock_codes = stock_codes[proc_id:] for stock_code in stock_codes: print("stock:", stock_code) FFC.FLS.load_all_financial_one_stock(stock_code) FFC.FLS.load_all_processed_stock_basic_one_stock([stock_code]) data_processed = FFC.financial_index_calc(stock_code) FFC.FLS.store_process_financical_data(data_processed, stock_code) proc_id = proc_id + 1 dr.write_index(proc_id)
def main_financial_statistic_process(path): store_path = os.path.join(path, 'statistic/') if not os.path.exists(store_path): os.makedirs(store_path) scu = SCU(path=path) stock_codes = scu.stock_codes_remove_no_stock_basic() FFC = financail_factor_statistic(path=path) sz50 = ts.get_sz50s() stock_codes = sz50['code'] stock_industry = ts.get_industry_classified() stock_codes = stock_industry[stock_industry['c_name'].isin(['房地产' ])]['code'] #stock_codes = stock_codes.pop('000527') #stock_codes = ['000001','000002','000004'] statistic_stock_data = {} statistic_stock_min_len = 100 for stock_code in stock_codes: print("stock:", stock_code) FFC.FLS.load_all_financial_one_stock(stock_code) FFC.FLS.load_all_processed_stock_basic_one_stock([stock_code]) data_processed = FFC.financial_index_calc(stock_code) (row, colum) = data_processed.shape if (row < statistic_stock_min_len): statistic_stock_min_len = row statistic_stock_data[stock_code] = data_processed #plt.figure() #data_processed.plot.bar(data_processed.index) sum_data = statistic_stock_data[stock_codes[0]].iloc[ -statistic_stock_min_len:, :] for stock_code in stock_codes[1:]: sum_data = sum_data + statistic_stock_data[stock_code].iloc[ -statistic_stock_min_len:, :] pct_data = sum_data.pct_change(periods=4) pct_data.to_csv(store_path + 'statistic_pct.csv') sum_data.to_csv(store_path + 'statistic_sum.csv')
pd_factor_values = pd.concat([pd_factor_values, factor_value], axis=1) pd_factor_values.columns = list_columns scu = SCU(path=self.path) pd_factor_values.index = scu.add_allstock_sh_sz(self.stock_codes) pd_factor_values.to_csv(self.path_factor_io, encoding='gbk') else: pd_factor_values = pd.read_csv(self.path_factor_io,index_col=0) return pd_factor_values if __name__ == '__main__': path = '../../../data/' path_factor = '../../../data/factor_io' print(FID['roe']) scu = SCU(path=path) stocks = scu.stock_codes_remove_no_stock_basic() stocks = ['000001','000002','000004','000005','000006'] dates = ['2018-06-30','2017-12-31']#,'2017-12-31' ffio = financial_factor_io(path=path, path_factor=path_factor, \ stocks = stocks, dates = dates,file_name = '1806_1712_1') indexs = [ #earning capacity FID['roe'],\ FID['roa'],\ FID['profit_revenue'],\ FID['profit_cost'],\ FID['equlity_incr_rate'],\ ###grow capacity FID['revenue_incr_rate'],\ FID['profit_incr_rate'],\ FID['cash_incr_rate'],\