Ejemplo n.º 1
0
 def test_complex(self):
     s1 = t_eval("Open / (Close - High)", data=self.data)
     s2 = self.data["Open"] / (self.data["Close"] - self.data["High"])
     v = mean_absolute_deviation(s1, s2)
     matching = nan_matching(s1, s2)
     self.assertTrue(v < THRESHOLD)
     self.assertTrue(matching)
Ejemplo n.º 2
0
 def test_div(self):
     s1 = t_eval("Open / Close", data=self.data)
     s2 = self.data["Open"] / self.data["Close"]
     v = mean_absolute_deviation(s1, s2)
     matching = nan_matching(s1, s2)
     self.assertTrue(v < THRESHOLD)
     self.assertTrue(matching)
Ejemplo n.º 3
0
 def test_rolling_mean_overflow(self):
     s1 = t_eval("mmean(Open, 10)", group_tag="windcode", data=self.data)
     df = self.data.groupby("windcode").apply(
         lambda df: df["Open"].rolling(10).mean()).reset_index()
     s2 = df["Open"]
     v = mean_absolute_deviation(s1, s2)
     matching = nan_matching(s1, s2)
     self.assertTrue(v < THRESHOLD or matching)
Ejemplo n.º 4
0
 def test_rolling_mean_global_params(self):
     s1 = t_eval("ma(Open, 2)", group_tag="windcode", data=self.data)
     df = self.data.groupby("windcode").apply(
         lambda df: df["Open"].rolling(2).mean()).reset_index()
     s2 = df["Open"]
     v = mean_absolute_deviation(s1, s2)
     matching = nan_matching(s1, s2)
     self.assertTrue(v < THRESHOLD)
     self.assertTrue(matching)
Ejemplo n.º 5
0
 def test_ewma(self):
     s1 = t_eval("ewm(Open, 2)", group_tag="windcode", data=self.data)
     df = self.data.groupby("windcode").apply(lambda d: d["Open"].ewm(
         span=2, min_periods=1).mean()).reset_index()
     s2 = df["Open"]
     v = mean_absolute_deviation(s1, s2)
     matching = nan_matching(s1, s2)
     self.assertTrue(v < THRESHOLD)
     self.assertTrue(matching)
Ejemplo n.º 6
0
 def test_rolling_corr(self):
     s1 = t_eval("mcorr(Open, Close, 2)",
                 group_tag="windcode",
                 data=self.data)
     df = self.data.groupby("windcode").apply(lambda df: df["Open"].rolling(
         2).corr(df["Close"].rolling(2))).reset_index()
     s2 = df[0]
     v = mean_absolute_deviation(s1, s2)
     self.assertTrue(v < THRESHOLD)
Ejemplo n.º 7
0
    def test_rank(self):
        def fun(df):
            df["or"] = df["Open"].rank()
            return df

        data = self.data.sort_values(["Date", "windcode"])
        data["s1"] = s1 = t_eval("rank(Open)", time_tag="Date", data=data)
        data["s2"] = s2 = data.groupby("Date").apply(fun)["or"]
        # print(data[["Date", "windcode", "Open", "s1", "s2"]])
        # print(data)
        v = mean_absolute_deviation(s1, s2)
        matching = nan_matching(s1, s2)
        self.assertTrue(v < THRESHOLD)
        self.assertTrue(matching)