import os from jt.utils.calendar.api_calendar import TradeCalendarDB from jt.utils.fs.utils import Utils as fsutils from jt.utils.misc.log import Logger calendardb = TradeCalendarDB() TODAY = calendardb.get_trading_date() # get T0 _logger = Logger(module_name_=__name__) def decompress_7Z(filePath_, save_dir_=None): """ decompress 7z files input: filepath_ : full path of 7z files _7z_path_ : .exe of 7z save_dir_ : save path """ _dir, _name = fsutils.extract_file_dir_and_name(filePath_) save_dir_ = _dir if save_dir_ is None else save_dir_ # os.system(f'decompress.bat {_root} {_7z_path_} {_dir} {_name} {save_dir_}') os.system(f'7z x {filePath_} -o{save_dir_}') def save_result(df_, db, table_name, keys_): _logger.info(f'Save result to DB {table_name}') db.upsert(table_name, df_=df_, keys_=keys_) def attach_security_type(df_): df_copy = df_.copy(deep=True) df_copy['security_type'] = df_copy['symbol'].apply(get_security_type)
MULTIPLIER_DICT = {'IC': 200, 'IF': 300, 'IH': 300} BENCHMARK = ['H00016.SH', 'H00300.CSI', 'H00905.CSI', 'H00852.SH'] _sec_type_default = 'UNKNOWN' _sec_type_stock = 'STOCK' _sec_type_stock_hk = 'HK' _sec_type_fund = 'FUND' _sec_type_oc = 'OC' _sec_type_repo = 'REPO' _sec_type_fx = 'FX' _sec_type_bond = 'BOND' _sec_type_index = 'INDEX' _sec_type_future = 'FUTURE' calendar = TradeCalendarDB() pgloader = PgSQLLoader() pgloader.set_db_config(read_cfg('cfg/db.ini', package='ps')['attribution']) log = Logger(module_name_=__name__) ALLOCATION = get_alloction() ALLOCATION = ALLOCATION.loc[ALLOCATION['strategy_id'].isin( ['91_JD1000', '55_ZF502'])] def get_multiplier(): def _inner(symbol): if str(symbol)[0:2] in MULTIPLIER_DICT.keys(): return MULTIPLIER_DICT[str(symbol)[0:2]] else: return 1 # stock -> 1