def get_index(start, end, benchmark): getdb = client_db.read_db(type='wind') sql = "select TRADE_DT,S_DQ_CLOSE from AIndexEODPrices where (TRADE_DT>='%s') and (TRADE_DT<='%s') and (S_INFO_WINDCODE = '%s')" % ( start, end, benchmark) df_index = getdb.db_query(sql) df_index.columns = ['trade_day', 'close'] return df_index
def __init__(self, start, flag, fre, factor_filename, day_range, dirpath, date=None): self.sql = "select s_info_windcode,trade_dt,s_dq_freeturnover from AShareEODDerivativeIndicator" self.flag = flag # 0 回测 1更新 self.day_range = day_range ## self.dirpath = dirpath # 新建data文件夹 存各种因子数据 self.factor_filename = factor_filename # data文件夹里 具体因子的文件夹 self.factor_path = self.dirpath + '/' + self.factor_filename # 确定运行日期 if date == None: self.today = strftime("%Y%m%d", localtime()) else: self.today = date self.initial = '20080101' # 留点窗口 为了下面start往前推能取到日期 self.start = start self.fre = fre self.all_trade_day = get_tradeDay.wind(self.initial, self.today, fre='day') ##用于定位一段交易日区间 self.trade_day = get_tradeDay.wind(self.start, self.today, fre=self.fre) # self.trade_day = self.trade_day.iloc[:-1] self.getdb = client_db.read_db(type='ctquant2') if not os.path.exists(self.dirpath): os.mkdir(self.dirpath) if not os.path.exists('%s' % (self.factor_path)): os.mkdir('%s' % (self.factor_path))
def run(start, end, today, dirpath, output_path, flag, fre): getdb = read_db(type='wind') tradeday = get_tradeDay.wind(start, end, fre=fre) tradeday = tradeday.iloc[:-1] # if not os.path.exists(dirpath): # os.mkdir(dirpath) if flag == 0: for day in tradeday: print(day) get_holding(day, dirpath, output_path, getdb) else: get_holding(today, dirpath, output_path, getdb)
def run(start, end, today, dirpath, flag, fre): getdb = client_db.read_db() tradeday = get_tradeDay.wind(start, end, fre=fre) tradeday = tradeday.iloc[:-1] if not os.path.exists(dirpath): os.mkdir(dirpath) if flag == 0: for day in tradeday: print(day) suspend(day, dirpath, getdb) else: suspend(today, dirpath, getdb)
def run(start, end, today, output_path, flag, fre): config_path = 'Z:/daily_data/config/config.yaml' with open(config_path) as f: config = yaml.load(f.read()) account = config['account'] for key, sub_account in account.items(): if sub_account['type'] == 'p': account_name = sub_account['subaccount'].split('account-')[1] getdb = read_db(type='wind') tradeday = get_tradeDay.wind(start, end, fre=fre) tradeday = tradeday.iloc[:-1] if flag == 0: for day in tradeday: print(day) get_new_stock(day, account_name, output_path, getdb) else: get_new_stock(today, account_name, output_path, getdb)
def __init__(self, start, end, fre, factor_name_list, type, benchmark, input_path, universe_path, n_quantile, outputpath): self.start = start self.end = end self.fre = fre self.factor_name_list = factor_name_list self.tradeday = get_tradeDay.wind(self.start, self.end, fre=self.fre) self.daily = get_tradeDay.wind(self.start, self.end, fre='day') self.type = type self.benchmark = benchmark self.input_path = input_path self.universe_path = universe_path self.n_quantile = n_quantile self.pct_quantiles = 1 / float(self.n_quantile) self.outputpath0 = outputpath self.getdb = client_db.read_db(type='wind')
def __init__(self, start, sql, flag, factor_filename, day_range, date=None): self.sql = sql self.flag = flag # 0 回测 1更新 self.day_range = day_range ## self.dirpath = 'raw_data' # 新建data文件夹 存各种因子数据 self.factor_filename = factor_filename # data文件夹里 具体因子的文件夹 self.factor_path = self.dirpath + '/' + self.factor_filename # 确定运行日期 if date == None: self.today = strftime("%Y%m%d", localtime()) else: self.today = date self.initial = '20170101' # 留点窗口 为了下面start往前推能取到日期 self.start = start self.all_trade_day = get_tradeDay.wind(self.initial, self.today, fre='day') ##用于定位一段交易日区间 self.trade_day = get_tradeDay.wind(self.start, self.today, fre='day') # self.trade_day = self.trade_day.iloc[:-1] self.getdb = client_db.read_db(type='ctquant2') if not os.path.exists(self.dirpath): os.mkdir(self.dirpath) if not os.path.exists('%s' % (self.factor_path)): os.mkdir('%s' % (self.factor_path))
end = strftime("%Y%m%d", localtime()) dirpath = 'gogo_data' update = False # day = '20171031' # sql = "select SYMBOL,LTDR from P_GG_KEYDATA where TDATE=%s" % day # test = client_db.read_db(type='gogo') # df = test.db_query(sql) if not os.path.exists(dirpath): os.mkdir(dirpath) fre = 'month' getdb = client_db.read_db(type='gogo') tradeday = get_tradeDay.wind(start, end, fre=fre) # tradeday = tradeday.iloc[:-1] today = tradeday.iloc[-1] def run(day, dirpath): sql = "select SYMBOL,LTDR from P_GG_KEYDATA where TDATE=%s" % (day) df = getdb.db_query(sql) df.columns = ['ticker', 'close_s'] df.to_csv('%s/close_%s.csv' % (dirpath, day), index=None) for day in tradeday: print(day)
import numpy as np start = '20061201' # start = '20110101' end = strftime("%Y%m%d", localtime()) output_path = 'F:/factor_data/raw_data' factor_name = 'PDPS' #'DEVIDEND' if not os.path.exists(output_path+'/'+factor_name): os.mkdir(output_path+'/'+factor_name) fre = 'month' trade_day = get_tradeDay.wind(start, end, fre=fre) getdb = client_db.read_db(type='wind') getdb2 = client_db.read_db(type='ctquant2') def get_timerange(today, sql): end = today start = str(int(today[:4]) - 3) + today[4:] sql1 = sql + " where (S_DIV_PRELANDATE >= %s) and (S_DIV_PRELANDATE <= %s)" % (start, end) df = getdb.db_query(sql1) return df def get_timerange2(today, sql): end = today start = str(int(today[:4]) - 3) + today[4:] sql1 = sql + " where (S_STM_ACTUAL_ISSUINGDATE >= %s) and (S_STM_ACTUAL_ISSUINGDATE <= %s)" % (start, end) df = getdb.db_query(sql1) return df
start = '20170901' end = strftime("%Y%m%d", localtime()) dirpath = 'data' update = False # sql = "select TRADE_DT,S_INFO_WINDCODE,S_DQ_ADJPRECLOSE,S_DQ_ADJOPEN,S_DQ_ADJHIGH,S_DQ_ADJLOW,S_DQ_ADJCLOSE,S_DQ_TRADESTATUS,S_DQ_ADJFACTOR from ASHAREEODPRICES where TRADE_DT>=%s and TRADE_DT<=%s"%(start,end) # getdb = client_db.read_db() # df = getdb.db_query(sql) if not os.path.exists(dirpath): os.mkdir(dirpath) fre = 'day' getdb = client_db.read_db() tradeday = get_tradeDay.wind(start, end, fre=fre) tradeday = tradeday.iloc[:-1] today = tradeday.iloc[-1] def run(day, dirpath): sql = "select TRADE_DT,S_INFO_WINDCODE,S_DQ_ADJPRECLOSE,S_DQ_ADJOPEN,S_DQ_ADJHIGH,S_DQ_ADJLOW,S_DQ_ADJCLOSE,S_DQ_TRADESTATUS from ASHAREEODPRICES where TRADE_DT=%s" % ( day) df = getdb.db_query(sql) df.columns = [ 'trade_day', 'code', 'adjpreclose', 'adjopen', 'adjhigh', 'adjlow', 'adjclose', 'status' ] df['status'] = df['status'].apply(lambda x: x.decode('gbk'))