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


Python AssetFinder.lifetimes方法代码示例

本文整理汇总了Python中zipline.assets.AssetFinder.lifetimes方法的典型用法代码示例。如果您正苦于以下问题:Python AssetFinder.lifetimes方法的具体用法?Python AssetFinder.lifetimes怎么用?Python AssetFinder.lifetimes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zipline.assets.AssetFinder的用法示例。


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

示例1: test_compute_lifetimes

# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lifetimes [as 别名]
    def test_compute_lifetimes(self, env=None):
        num_assets = 4
        trading_day = env.trading_day
        first_start = pd.Timestamp('2015-04-01', tz='UTC')

        frame = make_rotating_asset_info(
            num_assets=num_assets,
            first_start=first_start,
            frequency=env.trading_day,
            periods_between_starts=3,
            asset_lifetime=5
        )
        finder = AssetFinder(frame)

        all_dates = pd.date_range(
            start=first_start,
            end=frame.end_date.max(),
            freq=trading_day,
        )

        for dates in all_subindices(all_dates):
            expected_mask = full(
                shape=(len(dates), num_assets),
                fill_value=False,
                dtype=bool,
            )

            for i, date in enumerate(dates):
                it = frame[['start_date', 'end_date']].itertuples()
                for j, start, end in it:
                    if start <= date <= end:
                        expected_mask[i, j] = True

            # Filter out columns with all-empty columns.
            expected_result = pd.DataFrame(
                data=expected_mask,
                index=dates,
                columns=frame.sid.values,
            )
            actual_result = finder.lifetimes(dates)
            assert_frame_equal(actual_result, expected_result)
开发者ID:runtBlue,项目名称:zipline,代码行数:43,代码来源:test_assets.py

示例2: BaseFFCTestCase

# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lifetimes [as 别名]
class BaseFFCTestCase(TestCase):

    def setUp(self):
        self.__calendar = date_range('2014', '2015', freq=trading_day)
        self.__assets = assets = Int64Index(arange(1, 20))
        self.__finder = AssetFinder(
            make_simple_asset_info(
                assets,
                self.__calendar[0],
                self.__calendar[-1],
            ),
            db_path=':memory:',
            create_table=True,
        )
        self.__mask = self.__finder.lifetimes(self.__calendar[-10:])

    @property
    def default_shape(self):
        """Default shape for methods that build test data."""
        return self.__mask.shape

    def run_terms(self, terms, initial_workspace, mask=None):
        """
        Compute the given terms, seeding the workspace of our FFCEngine with
        `initial_workspace`.

        Parameters
        ----------
        terms : dict
            Mapping from termname -> term object.

        Returns
        -------
        results : dict
            Mapping from termname -> computed result.
        """
        engine = SimpleFFCEngine(
            ExplodingObject(),
            self.__calendar,
            self.__finder,
        )
        mask = mask if mask is not None else self.__mask
        return engine.compute_chunk(TermGraph(terms), mask, initial_workspace)

    def build_mask(self, array):
        ndates, nassets = array.shape
        return DataFrame(
            array,
            # Use the **last** N dates rather than the first N so that we have
            # space for lookbacks.
            index=self.__calendar[-ndates:],
            columns=self.__assets[:nassets],
            dtype=bool,
        )

    @with_default_shape
    def arange_data(self, shape, dtype=float):
        """
        Build a block of testing data from numpy.arange.
        """
        return arange(prod(shape), dtype=dtype).reshape(shape)

    @with_default_shape
    def randn_data(self, seed, shape):
        """
        Build a block of testing data from numpy.random.randn.
        """
        random_seed(seed)
        return randn(*shape)
开发者ID:runtBlue,项目名称:zipline,代码行数:71,代码来源:base.py


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