Beispiel #1
0
 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)
Beispiel #2
0
def indexRPSMain(n=10):
    # 显示rps排名前10%的中文名称
    # 股票代码
    code, data2 = getCode(excludeFileName='../testing/userFunc/zxgExclude.txt')
    rpsday = [10, 20, 50]
    # rpsday = [20, 50]
    days = 300 * 1.2
    start = datetime.datetime.now() - datetime.timedelta(days)
    end = datetime.datetime.now() - datetime.timedelta(0)
    # dfrps = _getRPS(rpsday, data2)
    rpsIndex = RPSIndex(code, start, end, rpsday)
    rpstopn = rpsIndex.rps()
    # print(rpstopn.head(20))
    print(rpstopn.tail(10))
    # 排名前n%
    # n = 40
    # fil = lambda x: (x['RPS20'] > 100 - n) | (x['RPS50'] > 100 - n)
    # fil = lambda x :[x['RPS{}'.format(item)] > 100-n  for item in rpsday]
    # rpstopn.loc[(rpstopn['RPS20'] > 100 - n) | (rpstopn['RPS50'] > 100 - n)]
    rpstopn = pd.concat([rpstopn.loc[(rpstopn[item] > 100 - n)] for item in rpstopn.columns])
    rpstopn.drop_duplicates(inplace=True)
    # rpstopn2 = rpsIndex.rpsTopN(end, n)
    rpstopn2 = rpsIndex.rpsTopN2(start, end, n)
    print(" 指数总数: {},RPS排名前{}% 的个数{}:\n".format(len(code), n, len(rpstopn)))
    print("日期: {}".format(end))
    print("rpstopn", rpstopn.tail(10))
    print("rpstopn2", rpstopn2.head(10))
    #  todo rpstopn concat rpstopn2
    return rpstopn2
Beispiel #3
0
 def test_rps_class_multi_rpsday(self):
     # 显示rps排名前10%的中文名称
     code = self.code
     rpsday = [20, 50, 120]
     dfrps = self._getRPS(rpsday, self.data2)
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.rps()
     self.assertTrue(dfrps.equals(rps), "RPS计算不匹配:\n{} {}".format(dfrps.head(), rps.head()))
     print(rps.tail())
Beispiel #4
0
 def test_rps_ETF_selectCode(self):
     # 显示rps排名前10%的中文名称
     fn = 'zxgETF.txt'
     # code列表
     code = read_zxg(fn)
     rpsday = [20, 50]
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.selectCode(code)
     # print(rps.tail())
     print(rps)
Beispiel #5
0
 def test_rps_class_selectCode(self):
     # 显示rps排名前10%的ETF中文名称
     code = self.code
     rpsday = [20, 50, 89]
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.selectCode(code[0])
     print(rps.tail())
     rps.plot()
     rps.plot(x='RPS20', y='RPS{}'.format(rpsday[1]))
     rps.plot(x='RPS20', y='RPS{}'.format(rpsday[2]))
     plt.show()
Beispiel #6
0
 def test_rps_class(self):
     """
     如果测试有错误,删除临时目录pickle文件
     """
     # 显示rps排名前10%的中文名称
     code = self.code
     rpsday = [20, 50]
     dfrps = self._getRPS(rpsday, self.data2)
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.rps()
     self.assertTrue(dfrps.equals(rps), "{} {}".format(dfrps.head(), rps.head()))
     print(rps.tail())
Beispiel #7
0
 def test_rps_ETF_selectCode(self):
     # rps筛选特定code
     fn = 'zxgETF.txt'
     # code列表
     code = read_zxg(fn)
     rpsday = [20, 50]
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.selectCode(code)
     # print(rps.tail())
     # print(rps)
     self.assertTrue(
         len(rpsIndex.selectCode(code[:2])) == 2 *
         len(rpsIndex.selectCode(code[:1])), "两倍长度")
Beispiel #8
0
    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)
Beispiel #9
0
 def test_rps_class_multi_rpsday(self):
     # 显示rps排名前10%的中文名称
     code = self.code
     rpsday = [20, 50, 120]
     dfrps = self._getRPS(rpsday, self.data2)
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.rps()
     try:
         self.assertTrue(
             dfrps.sort_values(dfrps.columns[0],
                               ascending=False).equals(rps),
             "排序后不相等 {} {}".format(dfrps, rps))
     except:
         self.assertTrue(dfrps.equals(rps), "不相等 {} {}".format(dfrps, rps))
     print(rps.tail())
Beispiel #10
0
 def test_rps_class(self):
     """
     如果测试有错误,删除临时目录pickle文件
     """
     # 显示rps排名前10%的中文名称
     code = self.code
     rpsday = [20, 50]
     dfrps = self._getRPS(rpsday, self.data2)
     rpsIndex = RPSIndex(code, self.start, self.end, rpsday)
     rps = rpsIndex.rps()
     try:
         self.assertTrue(
             dfrps.sort_values(dfrps.columns[0],
                               ascending=False).equals(rps),
             "排序后不相等 {} {}".format(dfrps, rps))
     except:
         self.assertTrue(dfrps.equals(rps), "不相等 {} {}".format(dfrps, rps))
     # self.assertTrue(dfrps.equals(rps), "{} {}".format(dfrps.head(), rps.head()))
     print(rps.tail())
     print(rps.head(20))
Beispiel #11
0
 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)