Esempio n. 1
0
    def test_get_period_ranges(self):

        test_wb = load_original_case(2)
        params = load_parameters_case(2)
        strategy_obj = ParameterDiscovery(test_wb, params)
        ws = strategy_obj.wb.active

        pr_d = pd.date_range("20020304", "20140410", freq="D")
        pr_m = pd.date_range("20020301", "20140301", freq="MS")

        period_ranges = list(strategy_obj._get_period_ranges(ws, params))

        self.assertTrue(compare_period_ranges(pr_d, period_ranges[0]))
        self.assertTrue(compare_period_ranges(pr_m, period_ranges[1]))
Esempio n. 2
0
    def test_compare_period_ranges(self):
        """Test a function to compare period ranges."""

        start = datetime.datetime(2015, 2, 16)
        end = datetime.datetime(2015, 5, 7)

        pr1 = pd.period_range(start, end, freq="D")
        pr2 = pd.period_range(start, periods=81, freq="D")
        pr3 = pd.period_range(end=end, periods=81)
        pr4 = pd.period_range(start, end, freq="M")
        pr5 = pd.period_range(start, end, freq="D", name="my_name")

        self.assertTrue(compare_period_ranges(pr1, pr2))
        self.assertTrue(compare_period_ranges(pr1, pr3))
        self.assertFalse(compare_period_ranges(pr1, pr4))
        self.assertTrue(compare_period_ranges(pr1, pr5))
Esempio n. 3
0
    def test_get_period_ranges_vertical(self):
        test_class = GetPeriodRangesMultifrequency
        wb = Workbook()
        ws = wb.active
        ws["A1"] = arrow.get(2000, 1, 1).datetime
        ws["A2"] = arrow.get(2000, 1, 1).datetime
        ws["A3"] = arrow.get(2000, 4, 1).datetime
        ws["A4"] = arrow.get(2000, 7, 1).datetime
        ws["A5"] = arrow.get(2000, 10, 1).datetime
        ws["A6"] = arrow.get(2001, 1, 1).datetime
        ws["A7"] = arrow.get(2001, 1, 1).datetime
        ws["A8"] = arrow.get(2001, 4, 1).datetime
        ws["A9"] = arrow.get(2001, 7, 1).datetime
        freq = "AQQQQ"
        ini_row = 1
        end_row = 9
        time_header_coord = "A1"
        time_alignement = 0
        alignment = "vertical"
        prs = test_class.get_period_ranges(ws, freq, ini_row,
                                           time_header_coord, end_row,
                                           time_alignement, alignment)
        pr_y = pd.date_range("20000101", "20010101", freq="AS")
        pr_q = pd.date_range("20000101", "20010701", freq="QS")

        self.assertTrue(compare_period_ranges(pr_y, prs[0]))
        self.assertTrue(compare_period_ranges(pr_q, prs[1]))

        # complete the frequency
        ws["A10"] = arrow.get(2001, 10, 1).datetime
        end_row = 10

        prs = test_class.get_period_ranges(ws, freq, ini_row,
                                           time_header_coord, end_row,
                                           time_alignement, alignment)
        pr_y = pd.date_range("20000101", "20010101", freq="AS")
        pr_q = pd.date_range("20000101", "20011001", freq="QS")

        self.assertTrue(compare_period_ranges(pr_y, prs[0]))
        self.assertTrue(compare_period_ranges(pr_q, prs[1]))
Esempio n. 4
0
    def test_get_period_ranges_horizontal(self):
        test_class = GetPeriodRangesMultifrequency
        wb = Workbook()
        ws = wb.active
        ws["A1"] = arrow.get(2000, 1, 1).datetime
        ws["B1"] = arrow.get(2000, 1, 1).datetime
        ws["C1"] = arrow.get(2000, 4, 1).datetime
        ws["D1"] = arrow.get(2000, 7, 1).datetime
        ws["E1"] = arrow.get(2000, 10, 1).datetime
        ws["F1"] = arrow.get(2001, 1, 1).datetime
        ws["G1"] = arrow.get(2001, 1, 1).datetime
        ws["H1"] = arrow.get(2001, 4, 1).datetime
        ws["I1"] = arrow.get(2001, 7, 1).datetime
        freq = "AQQQQ"
        ini_col = 1
        end_col = 9
        time_header_coord = "A1"
        time_alignement = 0
        alignment = "horizontal"
        prs = test_class.get_period_ranges(ws, freq, ini_col,
                                           time_header_coord, end_col,
                                           time_alignement, alignment)
        pr_y = pd.date_range("20000101", "20010101", freq="AS")
        pr_q = pd.date_range("20000101", "20010701", freq="QS")

        self.assertTrue(compare_period_ranges(pr_y, prs[0]))
        self.assertTrue(compare_period_ranges(pr_q, prs[1]))

        # complete the frequency
        ws["J1"] = arrow.get(2001, 10, 1).datetime
        end_col = 10

        prs = test_class.get_period_ranges(ws, freq, ini_col,
                                           time_header_coord, end_col,
                                           time_alignement, alignment)
        pr_y = pd.date_range("20000101", "20010101", freq="AS")
        pr_q = pd.date_range("20000101", "20011001", freq="QS")

        self.assertTrue(compare_period_ranges(pr_y, prs[0]))
        self.assertTrue(compare_period_ranges(pr_q, prs[1]))
Esempio n. 5
0
    def test_get_period_ranges_horizontal(self):
        test_class = GetPeriodRangesSingleFrequency
        wb = Workbook()
        ws = wb.active
        ws["A1"] = arrow.get(2000, 1, 1).datetime
        ws["B1"] = arrow.get(2000, 4, 1).datetime
        ws["C1"] = arrow.get(2000, 7, 1).datetime
        ws["D1"] = arrow.get(2000, 10, 1).datetime
        freq = "Q"
        ini_col = 1
        end_col = 4
        time_header_coord = "A1"
        time_alignement = 0
        alignment = "horizontal"
        prs = test_class.get_period_ranges(ws, freq, ini_col,
                                           time_header_coord, end_col,
                                           time_alignement, alignment)
        pr_q = pd.date_range("20000101", "20001001", freq="QS")

        self.assertTrue(compare_period_ranges(pr_q, prs[0]))