def insert_cnstock_all(): stockdao = cdao.cnstock_item_dao() dailydao = cdao.cnstock_daily_dao() stocklist = stockdao.get_all_tscode() existinglist = dailydao.get_existing_symbollist() for i in range(0, len(stocklist)): ts_code = stocklist[i] if ts_code not in existinglist: ts_code = ts_code.strip() print("reading %s from tushare..."%ts_code) try: list = ctu.read_cnstock_dailyandbasic(ts_code=ts_code, start_date='20140101', end_date='20190712') print("insert %s into database..."%ts_code) dailydao.insert_newlist(list) except (urllib3.exceptions.ReadTimeoutError, requests.exceptions.ReadTimeout) as err: print(str(err)) print("sleeping... 300s") time.sleep(300) print("retry....") i -= 1 except Exception as inst: print(type(inst)) print(inst.args) print(inst) i+=1
def insert_cnstock_fina(): daystr = util.get_today_datestr() cndaystr = util.date_us2cn(daystr) stkdao = cdao.cnstock_item_dao() stocklist = stkdao.get_all_tscode() list = ctu.read_cnstock_fina(stocklist, cndaystr) fina_dao = cdao.dao_cnstock_fina() fina_dao.add_oneItemEachTime(list)
def insert_cnstock_fina2(): daystr = util.get_today_datestr() cndaystr = util.date_us2cn(daystr) stkdao = cdao.cnstock_item_dao() sfadao = cdao.dao_cnstock_fina() stocklist = stkdao.get_all_tscode() existinglist = sfadao.get_existing_tscodelist() print('start fina2 insert...') for ts_code in stocklist: ts_code = ts_code.strip() if ts_code not in existinglist: list = ctu.read_cnstock_finaone(ts_code, cndaystr) sfadao.add_cnstock_fina(list)
def insert_cnstock_all_byodt(): stockdao = cdao.cnstock_item_dao() dailydao = cdao.cnstock_daily_dao() stocklist = stockdao.get_all_tscode() existinglist = dailydao.get_existing_symbollist() for i in range(0, len(stocklist)): ts_code = stocklist[i] if ts_code not in existinglist: ts_code = ts_code.strip() print("reading %s from opendatatool..."%ts_code) list = codt.read_cnstock_daily(ts_code=ts_code, start_date='2014-01-01', end_date='2019-07-12') print("insert %s into database..."%ts_code) dailydao.insert_newlist(list) i+=1
def insert_alldaily_oneday_cn(daystr): st_dao = cdao.cnstock_item_dao() sd_dao = cdao.cnstock_daily_dao() done_list = sd_dao.get_existing_symbollist2(daystr) print("the length of donelist: %d" %len(done_list)) daystr = util.date_us2cn(daystr) print("reading %s data from tushare..."%daystr) dl = ctu.read_cnstock_daily2(daystr) print("the length of read data: %d" %len(dl)) i = 0 to_add = [] for item in dl: if item.ts_code not in done_list: to_add.append(item) else: print("%s already exists in database...skipped." %item.ts_code) i+=1 print("totally %d skipped." %i) print("totally to be add: %d"%len(to_add)) print("insert into data base...") sd_dao.insert_newlist(to_add)
def get_samplelists_cn(symbolists, rows): stockdaily = cdbo.cnstock_daily_dao() list = [] for i in rows: s = symbolists[i] dict = stockdaily.get_onestocklists_alldays(s) if check_dataintegration(dict): stcal = scal.stock_cal(s, country='cn') stcal.read_data(dict) r1 = stcal.get_ma5up10_samplestargets() for item in r1: list.append(item) return list
def get_predictlist_cn(): symbolist = get_symbolists_cn() stockdaily = cdbo.cnstock_daily_dao() samplelist, labellist = [], [] if lock.acquire(1): for sy in symbolist: dict = stockdaily.get_onestocklists_alldays(sy) if check_dataintegration(dict): stockcal = scal.stock_cal(sy, country='cn') stockcal.read_data(dict) r = stockcal.get_predict_samples() if r is not None: samplelist.append(r) labellist.append(sy) samples = np.zeros( (len(samplelist), scal.SAMPLE_DATASIZE, scal.FEATURE_NUM)) for i in range(0, len(samplelist)): samples[i] = samplelist[i] list = [samples, labellist] lock.release() return list
def get_turnover(self, country): if country == 'us': stdb = udbo.dao_ussstock_item() rs = stdb.get_marketcap(self.symbol) marketcap = util.cmplx_toFloat(rs) size = len(self.closelist) tr = np.zeros(size, dtype=float) for i in range(0, size): if marketcap != 0: tr[i] = (self.closelist[i] * self.vollist[i]) / marketcap else: tr[i] = 0 return tr else: stdb = cdbo.cnstock_daily_dao() list = stdb.get_turnoverratio_list(self.symbol) if len(list) == len(self.closelist): return list else: print("turnover rate leng != datasize") tr = np.zeros(len(self.closelist), dtype=float) return tr
def insert_predictresult_cn(list): pr_dao = cdao.dao_cnstock_result() for item in list: to_add=[] to_add.append(item) pr_dao.add_predict_result(to_add)
def insert_cnstock_compnay(): company_dao = cdao.dao_cnstock_company() company_ts = ctu.read_cnstock_company() company_dao.add_cnstock_company(company_ts)
def insert_cnstocklist(): stocklist = ctu.read_cnstocklist() stockdao = cdao.cnstock_item_dao() stockdao.insert_newlist(stocklist)
def get_latestdatefromdaily_cn(symbol): cd_dao = cdao.cnstock_daily_dao() dt = cd_dao.get_latesttradedate(symbol) return dt
def get_symbolists_cn(): stockitem = cdbo.cnstock_item_dao() symbol = stockitem.get_all_tscode() return symbol