def test_RPSIndex_rpsTopN2(self): # 显示rps排名前10%的ETF中文名称 fn = 'zxgETF.txt' # code列表 code = read_zxg(fn) rpsday = [20, 50] end = self.end # end = "2020-06-24" rpsIndex = RPSIndex(code, self.start, end, rpsday) n = 10 rps = rpsIndex.rpsTopN2(startday=end, percentN=n) rps2 = rpsIndex.rpsTopN(end, n) self.assertTrue(len(rps) > 0) self.assertTrue( len(rps) == len(rps2), "长度不同 {} {}\n{} {}".format(len(rps), len(rps2), rps, rps2)) try: self.assertTrue( rps.sort_values(rps.columns[0], ascending=False).equals(rps2), "排序后不相等 {} {}".format(rps, rps2)) except: self.assertTrue(rps.equals(rps2), "不相等 {} {}".format(rps, rps2)) print(rps) print("总数: {}".format(len(rps))) dfInfo = codeInfo(list(rps.index.levels[1])) print(dfInfo.name)
def test_ETFName(self): """文件zxgFile,增加中文名称 """ zxgFile = "zxgETF.txt" code = read_zxg(zxgFile) dfInfo = codeInfo(list(code)) print(dfInfo) dfInfo[['code', 'name']].to_csv(zxgFile, index=False, sep=" ", header=None)
def test_readzxg_name(self): """代码对应的指数名称 """ fn = 'zxg.txt' # code列表 code = read_zxg(fn) data = qa.QA_fetch_index_list_adv() print(data.columns) # print(data[['code', 'name']]) for c in code: print(c, data.loc[c]['name']) df =codeInfo(code) print(df.head()) self.assertTrue(len(code) == len(df), "股票代码个数和股票信息的个数相同")
def test_rps_ETFTOPN(self): # 显示rps排名前10%的ETF中文名称 fn = 'zxgETF.txt' # code列表 code = read_zxg(fn) rpsday = [20, 50] rpsIndex = RPSIndex(code, self.start, self.end, rpsday) n = 10 rps = rpsIndex.rpsTopN(self.end, n) self.assertTrue(len(rps) > 0) print(rps) print("总数: {}".format(len(rps))) dfInfo = codeInfo(list(rps.index.levels[1])) print(dfInfo.name)
def test_RPSIndex_rpsTopN2_2(self): # 一段时间内,显示rps排名前10%的ETF中文名称 fn = 'zxgETF.txt' # code列表 code = read_zxg(fn) rpsday = [20, 50] rpsIndex = RPSIndex(code, self.start, self.end, rpsday) n = 10 start = self.end - datetime.timedelta(10) rps = rpsIndex.rpsTopN2(startday=start, lastday=self.end, percentN=n) self.assertTrue(len(rps) > 0) # for day in reversed(rps.index.levels[0]): for day in rps.index.levels[0]: if day == pd.to_datetime(datetime.date(2020, 6, 30)): continue print("对比日期: {}".format(day)) rps2 = rpsIndex.rpsTopN(day, n) df = rps.loc[(slice(pd.Timestamp(day), pd.Timestamp(day))), :] self.assertTrue( len(df) == len(rps2), "长度不同 {} {}\n{} {}".format(len(df), len(rps2), rps, rps2)) try: obo = self.differOneByOne(df, rps2) self.assertTrue(len(obo) == 0, "{} {}".format(df, rps2)) self.assertTrue(df.equals(rps2), "不相等 {} {}".format(df, rps2)) except Exception as e: df = df.sort_values(by=df.columns[0], ascending=False, inplace=False) obo = self.differOneByOne(df, rps2) self.assertTrue(len(obo) == 0, "{} {}".format(df, rps2)) self.assertTrue(df.equals(rps2), "不相等 {} {}".format(df, rps2)) print(rps) print("总数: {}".format(len(rps))) dfInfo = codeInfo(list(rps.index.levels[1])) print(dfInfo.name)