Exemplo n.º 1
0
    def test_normal(self):
        days_to_use = self.sim_params.sessions[1:]

        source = BenchmarkSource(self.asset_finder.retrieve_asset(1),
                                 self.trading_calendar, days_to_use,
                                 self.data_portal)

        # should be the equivalent of getting the price history, then doing
        # a pct_change on it
        manually_calculated = self.data_portal.get_history_window(
            [1],
            days_to_use[-1],
            len(days_to_use),
            "1d",
            "close",
            "daily",
        )[1].pct_change()

        # compare all the fields except the first one, for which we don't have
        # data in manually_calculated
        for idx, day in enumerate(days_to_use[1:]):
            self.assertEqual(source.get_value(day),
                             manually_calculated[idx + 1])

        # compare a slice of the data
        assert_series_equal(source.get_range(days_to_use[1], days_to_use[10]),
                            manually_calculated[1:11])
    def test_normal(self):
        days_to_use = self.sim_params.sessions[1:]

        source = BenchmarkSource(
            self.env.asset_finder.retrieve_asset(1),
            self.trading_calendar,
            days_to_use,
            self.data_portal
        )

        # should be the equivalent of getting the price history, then doing
        # a pct_change on it
        manually_calculated = self.data_portal.get_history_window(
            [1],
            days_to_use[-1],
            len(days_to_use),
            "1d",
            "close",
            "daily",
        )[1].pct_change()

        # compare all the fields except the first one, for which we don't have
        # data in manually_calculated
        for idx, day in enumerate(days_to_use[1:]):
            self.assertEqual(
                source.get_value(day),
                manually_calculated[idx + 1]
            )

        # compare a slice of the data
        assert_series_equal(
            source.get_range(days_to_use[1], days_to_use[10]),
            manually_calculated[1:11]
        )