当前位置: 首页>>代码示例>>Python>>正文


Python test_algorithms.BatchTransformAlgorithm类代码示例

本文整理汇总了Python中zipline.test_algorithms.BatchTransformAlgorithm的典型用法代码示例。如果您正苦于以下问题:Python BatchTransformAlgorithm类的具体用法?Python BatchTransformAlgorithm怎么用?Python BatchTransformAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BatchTransformAlgorithm类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_event_window

    def test_event_window(self):
        algo = BatchTransformAlgorithm()
        algo.run(self.source)
        wl = algo.window_length
        # The following assertion depend on window length of 3
        self.assertEqual(wl, 3)
        self.assertEqual(
            algo.history_return_price_class[:wl],
            [None] * wl,
            "First three iterations should return None."
            + "\n"
            + "i.e. no returned values until window is full'"
            + "%s" % (algo.history_return_price_class,),
        )
        self.assertEqual(
            algo.history_return_price_decorator[:wl],
            [None] * wl,
            "First three iterations should return None."
            + "\n"
            + "i.e. no returned values until window is full'"
            + "%s" % (algo.history_return_price_decorator,),
        )
        # After three Nones, the next value should be a data frame
        self.assertTrue(isinstance(algo.history_return_price_class[wl], pd.DataFrame))

        # Test whether arbitrary fields can be added to datapanel
        field = algo.history_return_arbitrary_fields[-1]
        self.assertTrue("arbitrary" in field.items, "datapanel should contain column arbitrary")

        self.assertTrue(
            all(field["arbitrary"].values.flatten() == [123] * algo.window_length),
            'arbitrary dataframe should contain only "test"',
        )

        for data in algo.history_return_sid_filter[wl:]:
            self.assertIn(0, data.columns)
            self.assertNotIn(1, data.columns)

        for data in algo.history_return_field_filter[wl:]:
            self.assertIn("price", data.items)
            self.assertNotIn("ignore", data.items)

        for data in algo.history_return_field_no_filter[wl:]:
            self.assertIn("price", data.items)
            self.assertIn("ignore", data.items)

        for data in algo.history_return_ticks[wl:]:
            self.assertTrue(isinstance(data, deque))

        for data in algo.history_return_not_full:
            self.assertIsNot(data, None)

        # test overloaded class
        for test_history in [algo.history_return_price_class, algo.history_return_price_decorator]:
            # starting at window length, the window should contain
            # consecutive (of window length) numbers up till the end.
            for i in range(algo.window_length, len(test_history)):
                np.testing.assert_array_equal(
                    range(i - algo.window_length + 1, i + 1), test_history[i].values.flatten()
                )
开发者ID:gawecoti,项目名称:zipline,代码行数:60,代码来源:test_transforms.py

示例2: test_event_window

    def test_event_window(self):
        algo = BatchTransformAlgorithm()
        algo.run(self.source)

        self.assertEqual(algo.history_return_price_class[:2],
                         [None, None],
                         "First two iterations should return None")
        self.assertEqual(algo.history_return_price_decorator[:2],
                         [None, None],
                         "First two iterations should return None")
        self.assertEqual(algo.history_return_price_market_aware[:2],
                         [None, None],
                         "First two iterations should return None")

        # test overloaded class
        for test_history in [algo.history_return_price_class,
                             algo.history_return_price_decorator]:
            np.testing.assert_array_equal(
                    range(2, 8),
                    test_history[2].values.flatten()
            )

            np.testing.assert_array_equal(
                    range(2, 8),
                    test_history[3].values.flatten()
            )

            np.testing.assert_array_equal(
                    range(4, 12),
                    test_history[4].values.flatten()
            )
开发者ID:snth,项目名称:zipline,代码行数:31,代码来源:test_transforms.py

示例3: test_event_window

    def test_event_window(self):
        algo = BatchTransformAlgorithm()
        algo.run(self.source)
        wl = algo.window_length
        self.assertEqual(algo.history_return_price_class[:wl],
                         [None] * wl,
                         "First two iterations should return None")
        self.assertEqual(algo.history_return_price_decorator[:wl],
                         [None] * wl,
                         "First two iterations should return None")
        self.assertTrue(isinstance(
            algo.history_return_price_class[wl + 1],
            pd.DataFrame)
        )

        # Test whether arbitrary fields can be added to datapanel
        field = algo.history_return_arbitrary_fields[-1]
        self.assertTrue(
            'arbitrary' in field.items,
            'datapanel should contain column arbitrary'
        )

        self.assertTrue(all(
            field['arbitrary'].values.flatten() ==
            [123] * algo.window_length),
            'arbitrary dataframe should contain only "test"'
        )

        for data in algo.history_return_sid_filter[wl:]:
            self.assertIn(0, data.columns)
            self.assertNotIn(1, data.columns)

        for data in algo.history_return_field_filter[wl:]:
            self.assertIn('price', data.items)
            self.assertNotIn('ignore', data.items)

        for data in algo.history_return_field_no_filter[wl:]:
            self.assertIn('price', data.items)
            self.assertIn('ignore', data.items)

        for data in algo.history_return_ticks[wl:]:
            self.assertTrue(isinstance(data, deque))

        for data in algo.history_return_not_full:
            self.assertIsNot(data, None)

        # test overloaded class
        for test_history in [algo.history_return_price_class,
                             algo.history_return_price_decorator]:
            # starting at window length, the window should contain
            # consecutive (of window length) numbers up till the end.
            for i in range(algo.window_length, len(test_history)):
                np.testing.assert_array_equal(
                    range(i - algo.window_length + 1, i + 1),
                    test_history[i].values.flatten()
                )
开发者ID:Elektra58,项目名称:zipline,代码行数:56,代码来源:test_transforms.py

示例4: test_passing_of_args

    def test_passing_of_args(self):
        algo = BatchTransformAlgorithm(1, kwarg='str')
        self.assertEqual(algo.args, (1,))
        self.assertEqual(algo.kwargs, {'kwarg': 'str'})

        algo.run(self.source)
        expected_item = ((1, ), {'kwarg': 'str'})
        self.assertEqual(
            algo.history_return_args,
            [None, None, expected_item, expected_item,
             expected_item, expected_item])
开发者ID:snth,项目名称:zipline,代码行数:11,代码来源:test_transforms.py

示例5: test_core_functionality

 def test_core_functionality(self):
     algo = BatchTransformAlgorithm(sim_params=self.sim_params)
     algo.run(self.source)
     wl = algo.window_length
     # The following assertion depend on window length of 3
     self.assertEqual(wl, 3)
     # If window_length is 3, there should be 2 None events, as the
     # window fills up on the 3rd day.
     n_none_events = 2
     self.assertEqual(algo.history_return_price_class[:n_none_events],
                      [None] * n_none_events,
                      "First two iterations should return None." + "\n" +
                      "i.e. no returned values until window is full'" +
                      "%s" % (algo.history_return_price_class,))
开发者ID:CarterBain,项目名称:AlephNull,代码行数:14,代码来源:test_batchtransform.py

示例6: test_passing_of_args

    def test_passing_of_args(self):
        algo = BatchTransformAlgorithm(1, kwarg='str')
        self.assertEqual(algo.args, (1,))
        self.assertEqual(algo.kwargs, {'kwarg': 'str'})

        algo.run(self.source)
        expected_item = ((1, ), {'kwarg': 'str'})
        self.assertEqual(
            algo.history_return_args,
            [
                # 1990-01-03 - window not full
                None,
                # 1990-01-04 - window not full
                None,
                # 1990-01-05 - window not full, 3rd event
                None,
                # 1990-01-08 - window now full
                expected_item
            ])
开发者ID:snoopying,项目名称:zipline,代码行数:19,代码来源:test_transforms.py

示例7: test_event_window

    def test_event_window(self):
        algo = BatchTransformAlgorithm()
        algo.run(self.source)

        self.assertEqual(algo.history_return_price_class[:2],
                         [None, None],
                         "First two iterations should return None")
        self.assertEqual(algo.history_return_price_decorator[:2],
                         [None, None],
                         "First two iterations should return None")
        self.assertEqual(algo.history_return_price_market_aware[:2],
                         [None, None],
                         "First two iterations should return None")
        self.assertEqual(algo.history_return_more_days_than_refresh[:3],
                         [None, None, None],
                         "First five iterations should return None")
        self.assertTrue(isinstance(
            algo.history_return_more_days_than_refresh[4],
            pd.DataFrame),
            "Sixth iteration should not be None"
        )

        # test overloaded class
        for test_history in [algo.history_return_price_class,
                             algo.history_return_price_decorator]:
            np.testing.assert_array_equal(
                range(2, 8),
                test_history[2].values.flatten()
            )

            np.testing.assert_array_equal(
                range(2, 8),
                test_history[3].values.flatten()
            )

            np.testing.assert_array_equal(
                range(4, 12),
                test_history[4].values.flatten()
            )
开发者ID:andycwang,项目名称:zipline,代码行数:39,代码来源:test_transforms.py

示例8: test_passing_of_args

    def test_passing_of_args(self):
        algo = BatchTransformAlgorithm(1, kwarg='str',
                                       sim_params=self.sim_params,
                                       env=self.env)
        algo.run(self.source)
        self.assertEqual(algo.args, (1,))
        self.assertEqual(algo.kwargs, {'kwarg': 'str'})

        expected_item = ((1, ), {'kwarg': 'str'})
        self.assertEqual(
            algo.history_return_args,
            [
                # 1990-01-01 - market holiday, no event
                # 1990-01-02 - window not full
                None,
                # 1990-01-03 - window not full
                None,
                # 1990-01-04 - window now full, 3rd event
                expected_item,
                # 1990-01-05 - window now full
                expected_item,
                # 1990-01-08 - window now full
                expected_item
            ])
开发者ID:HectorZarate,项目名称:zipline,代码行数:24,代码来源:test_batchtransform.py

示例9: test_core_functionality

    def test_core_functionality(self):
        algo = BatchTransformAlgorithm(sim_params=self.sim_params)
        algo.run(self.source)
        wl = algo.window_length
        # The following assertion depend on window length of 3
        self.assertEqual(wl, 3)
        # If window_length is 3, there should be 2 None events, as the
        # window fills up on the 3rd day.
        n_none_events = 2
        self.assertEqual(algo.history_return_price_class[:n_none_events],
                         [None] * n_none_events,
                         "First two iterations should return None." + "\n" +
                         "i.e. no returned values until window is full'" +
                         "%s" % (algo.history_return_price_class,))
        self.assertEqual(algo.history_return_price_decorator[:n_none_events],
                         [None] * n_none_events,
                         "First two iterations should return None." + "\n" +
                         "i.e. no returned values until window is full'" +
                         "%s" % (algo.history_return_price_decorator,))

        # After three Nones, the next value should be a data frame
        self.assertTrue(isinstance(
            algo.history_return_price_class[wl],
            pd.DataFrame)
        )

        # Test whether arbitrary fields can be added to datapanel
        field = algo.history_return_arbitrary_fields[-1]
        self.assertTrue(
            'arbitrary' in field.items,
            'datapanel should contain column arbitrary'
        )

        self.assertTrue(all(
            field['arbitrary'].values.flatten() ==
            [123] * algo.window_length),
            'arbitrary dataframe should contain only "test"'
        )

        for data in algo.history_return_sid_filter[wl:]:
            self.assertIn(0, data.columns)
            self.assertNotIn(1, data.columns)

        for data in algo.history_return_field_filter[wl:]:
            self.assertIn('price', data.items)
            self.assertNotIn('ignore', data.items)

        for data in algo.history_return_field_no_filter[wl:]:
            self.assertIn('price', data.items)
            self.assertIn('ignore', data.items)

        for data in algo.history_return_ticks[wl:]:
            self.assertTrue(isinstance(data, deque))

        for data in algo.history_return_not_full:
            self.assertIsNot(data, None)

        # test overloaded class
        for test_history in [algo.history_return_price_class,
                             algo.history_return_price_decorator]:
            # starting at window length, the window should contain
            # consecutive (of window length) numbers up till the end.
            for i in range(algo.window_length, len(test_history)):
                np.testing.assert_array_equal(
                    range(i - algo.window_length + 2, i + 2),
                    test_history[i].values.flatten()
                )
开发者ID:99plus2,项目名称:zipline,代码行数:67,代码来源:test_batchtransform.py


注:本文中的zipline.test_algorithms.BatchTransformAlgorithm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。