• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python factory.create_returns_from_range函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_treasury_returns

    def test_treasury_returns(self):
        returns = factory.create_returns_from_range(self.sim_params)
        metrics = risk.RiskReport(returns,
                                  self.sim_params,
                                  trading_calendar=self.trading_calendar,
                                  benchmark_returns=self.env.benchmark_returns)

        # These values are all expected to be zero because we explicity zero
        # out the treasury period returns as they are no longer actually used.
        self.assertEqual(
          [x.treasury_period_return for x in metrics.month_periods],
          [0.0] * len(metrics.month_periods),
        )
        self.assertEqual(
          [x.treasury_period_return for x in metrics.three_month_periods],
          [0.0] * len(metrics.three_month_periods),
        )
        self.assertEqual(
          [x.treasury_period_return for x in metrics.six_month_periods],
          [0.0] * len(metrics.six_month_periods),
        )
        self.assertEqual(
          [x.treasury_period_return for x in metrics.year_periods],
          [0.0] * len(metrics.year_periods),
        )
开发者ID:SJCosgrove,项目名称:quantopianresearch,代码行数:25,代码来源:test_risk_period.py


示例2: test_trading_days_06

 def test_trading_days_06(self):
     returns = factory.create_returns_from_range(self.trading_env)
     metrics = risk.RiskReport(returns, self.trading_env)
     self.assertEqual([x.trading_days for x in metrics.year_periods],
                      [251])
     self.assertEqual([x.trading_days for x in metrics.month_periods],
                      [20, 19, 23, 19, 22, 22, 20, 23, 20, 22, 21, 20])
开发者ID:aichi,项目名称:zipline,代码行数:7,代码来源:test_risk.py


示例3: test_partial_month

    def test_partial_month(self):

        start_session = self.trading_calendar.minute_to_session_label(
            pd.Timestamp("1993-02-01", tz='UTC')
        )

        # 1992 and 1996 were leap years
        total_days = 365 * 5 + 2
        end_session = start_session + datetime.timedelta(days=total_days)
        sim_params90s = SimulationParameters(
            start_session=start_session,
            end_session=end_session,
            trading_calendar=self.trading_calendar,
        )

        returns = factory.create_returns_from_range(sim_params90s)
        returns = returns[:-10]  # truncate the returns series to end mid-month
        metrics = ClassicRiskMetrics.risk_report(
            algorithm_returns=returns,
            # use returns from the fixture to ensure that we have enough data.
            benchmark_returns=self.BENCHMARK_RETURNS,
            algorithm_leverages=pd.Series(0.0, index=returns.index)
        )
        total_months = 60
        self.check_metrics(metrics, total_months, start_session)
开发者ID:barrygolden,项目名称:zipline,代码行数:25,代码来源:test_risk.py


示例4: test_partial_month

    def test_partial_month(self):

        start = datetime.datetime(
            year=1991,
            month=1,
            day=1,
            hour=0,
            minute=0,
            tzinfo=pytz.utc)

        # 1992 and 1996 were leap years
        total_days = 365 * 5 + 2
        end = start + datetime.timedelta(days=total_days)
        sim_params90s = SimulationParameters(
            period_start=start,
            period_end=end,
            trading_schedule=self.trading_schedule,
        )

        returns = factory.create_returns_from_range(sim_params90s)
        returns = returns[:-10]  # truncate the returns series to end mid-month
        metrics = risk.RiskReport(returns, sim_params90s,
                                  trading_schedule=self.trading_schedule,
                                  treasury_curves=self.env.treasury_curves,
                                  benchmark_returns=self.env.benchmark_returns)
        total_months = 60
        self.check_metrics(metrics, total_months, start)
开发者ID:ABDieng,项目名称:zipline,代码行数:27,代码来源:test_risk_period.py


示例5: test_benchmark_volatility_06

    def test_benchmark_volatility_06(self):
        returns = factory.create_returns_from_range(self.sim_params)
        metrics = risk.RiskReport(returns, self.sim_params)
        answer_key_month_periods = ANSWER_KEY.get_values(
            AnswerKey.BENCHMARK_PERIOD_VOLATILITY['Monthly'],
            decimal=3)
        self.assertEqual([np.round(x.benchmark_volatility, 3)
                          for x in metrics.month_periods],
                         answer_key_month_periods)

        answer_key_three_month_periods = ANSWER_KEY.get_values(
            AnswerKey.BENCHMARK_PERIOD_VOLATILITY['3-Month'],
            decimal=3)
        self.assertEqual([np.round(x.benchmark_volatility, 3)
                          for x in metrics.three_month_periods],
                         answer_key_three_month_periods)

        answer_key_six_month_periods = ANSWER_KEY.get_values(
            AnswerKey.BENCHMARK_PERIOD_VOLATILITY['6-month'],
            decimal=3)
        self.assertEqual([np.round(x.benchmark_volatility, 3)
                          for x in metrics.six_month_periods],
                         answer_key_six_month_periods)

        answer_key_year_periods = ANSWER_KEY.get_values(
            AnswerKey.BENCHMARK_PERIOD_VOLATILITY['year'],
            decimal=3)
        self.assertEqual([np.round(x.benchmark_volatility, 3)
                          for x in metrics.year_periods],
                         answer_key_year_periods)
开发者ID:Vanza1,项目名称:zipline,代码行数:30,代码来源:test_risk.py


示例6: test_trading_days_08

    def test_trading_days_08(self):
        returns = factory.create_returns_from_range(self.sim_params08)
        metrics = risk.RiskReport(returns, self.sim_params08)
        self.assertEqual([x.trading_days for x in metrics.year_periods],
                         [253])

        self.assertEqual([x.trading_days for x in metrics.month_periods],
                         [21, 20, 20, 22, 21, 21, 22, 21, 21, 23, 19, 22])
开发者ID:PostPCEra,项目名称:zipline,代码行数:8,代码来源:test_risk.py


示例7: check_year_range

 def check_year_range(self, start_date, years):
     sim_params = SimulationParameters(
         period_start=start_date, period_end=start_date.replace(year=(start_date.year + years)), env=self.env
     )
     returns = factory.create_returns_from_range(sim_params)
     metrics = risk.RiskReport(returns, self.sim_params, env=self.env)
     total_months = years * 12
     self.check_metrics(metrics, total_months, start_date)
开发者ID:maartenb,项目名称:zipline,代码行数:8,代码来源:test_risk_period.py


示例8: test_trading_days_06

 def test_trading_days_06(self):
     returns = factory.create_returns_from_range(self.sim_params)
     metrics = risk.RiskReport(returns, self.sim_params,
                               trading_calendar=self.trading_calendar,
                               treasury_curves=self.env.treasury_curves,
                               benchmark_returns=self.env.benchmark_returns)
     self.assertEqual([x.num_trading_days for x in metrics.year_periods],
                      [251])
     self.assertEqual([x.num_trading_days for x in metrics.month_periods],
                      [20, 19, 23, 19, 22, 22, 20, 23, 20, 22, 21, 20])
开发者ID:4ever911,项目名称:zipline,代码行数:10,代码来源:test_risk_period.py


示例9: test_trading_days_08

    def test_trading_days_08(self):
        returns = factory.create_returns_from_range(self.sim_params08)
        metrics = risk.RiskReport(returns, self.sim_params08,
                                  trading_schedule=self.trading_schedule,
                                  treasury_curves=self.env.treasury_curves,
                                  benchmark_returns=self.env.benchmark_returns)
        self.assertEqual([x.num_trading_days for x in metrics.year_periods],
                         [253])

        self.assertEqual([x.num_trading_days for x in metrics.month_periods],
                         [21, 20, 20, 22, 21, 21, 22, 21, 21, 23, 19, 22])
开发者ID:ABDieng,项目名称:zipline,代码行数:11,代码来源:test_risk_period.py


示例10: check_year_range

 def check_year_range(self, start_date, years):
     sim_params = SimulationParameters(
         period_start=start_date,
         period_end=start_date.replace(year=(start_date.year + years)),
         trading_schedule=self.trading_schedule,
     )
     returns = factory.create_returns_from_range(sim_params)
     metrics = risk.RiskReport(returns, self.sim_params,
                               trading_schedule=self.trading_schedule,
                               treasury_curves=self.env.treasury_curves,
                               benchmark_returns=self.env.benchmark_returns)
     total_months = years * 12
     self.check_metrics(metrics, total_months, start_date)
开发者ID:ABDieng,项目名称:zipline,代码行数:13,代码来源:test_risk_period.py


示例11: test_benchmark_volatility_08

    def test_benchmark_volatility_08(self):
        returns = factory.create_returns_from_range(self.sim_params08)
        metrics = risk.RiskReport(returns, self.sim_params08,
                                  trading_calendar=self.trading_calendar,
                                  treasury_curves=self.env.treasury_curves,
                                  benchmark_returns=self.env.benchmark_returns)

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.month_periods],
                         [0.07,
                          0.058,
                          0.082,
                          0.054,
                          0.041,
                          0.057,
                          0.068,
                          0.06,
                          0.157,
                          0.244,
                          0.195,
                          0.145])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.three_month_periods],
                         [0.12,
                          0.113,
                          0.105,
                          0.09,
                          0.098,
                          0.107,
                          0.179,
                          0.293,
                          0.344,
                          0.34])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.six_month_periods],
                         [0.15,
                          0.149,
                          0.15,
                          0.2,
                          0.308,
                          0.36,
                          0.383])
        # TODO: ugly, but I can't get the rounded float to match.
        # maybe we need a different test that checks the
        # difference between the numbers
        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.year_periods],
                         [0.411])
开发者ID:4ever911,项目名称:zipline,代码行数:50,代码来源:test_risk_period.py


示例12: test_treasury_returns

    def test_treasury_returns(self):
        returns = factory.create_returns_from_range(self.sim_params)
        metrics = ClassicRiskMetrics.risk_report(
            algorithm_returns=returns,
            benchmark_returns=self.env.benchmark_returns,
            algorithm_leverages=pd.Series(0.0, index=returns.index)
        )

        # These values are all expected to be zero because we explicity zero
        # out the treasury period returns as they are no longer actually used.
        for period in PERIODS:
            self.assertEqual(
              [x['treasury_period_return'] for x in metrics[period]],
              [0.0] * len(metrics[period]),
            )
开发者ID:zhou,项目名称:zipline,代码行数:15,代码来源:test_risk.py


示例13: test_benchmark_returns_08

    def test_benchmark_returns_08(self):
        returns = factory.create_returns_from_range(self.sim_params08)
        metrics = risk.RiskReport(returns, self.sim_params08,
                                  trading_calendar=self.trading_calendar,
                                  treasury_curves=self.env.treasury_curves,
                                  benchmark_returns=self.env.benchmark_returns)

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.month_periods],
                         [-0.061,
                          -0.035,
                          -0.006,
                          0.048,
                          0.011,
                          -0.086,
                          -0.01,
                          0.012,
                          -0.091,
                          -0.169,
                          -0.075,
                          0.008])

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.three_month_periods],
                         [-0.099,
                          0.005,
                          0.052,
                          -0.032,
                          -0.085,
                          -0.084,
                          -0.089,
                          -0.236,
                          -0.301,
                          -0.226])

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.six_month_periods],
                         [-0.128,
                          -0.081,
                          -0.036,
                          -0.118,
                          -0.301,
                          -0.36,
                          -0.294])

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.year_periods],
                         [-0.385])
开发者ID:4ever911,项目名称:zipline,代码行数:48,代码来源:test_risk_period.py


示例14: test_benchmark_returns_08

    def test_benchmark_returns_08(self):
        returns = factory.create_returns_from_range(self.trading_env08)
        metrics = risk.RiskReport(returns, self.trading_env08)

        monthly = [round(x.benchmark_period_returns, 3)
                   for x in metrics.month_periods]

        self.assertEqual(monthly,
                         [-0.051,
                          -0.039,
                          0.001,
                          0.043,
                          0.011,
                          -0.075,
                          -0.007,
                          0.026,
                          -0.093,
                          -0.160,
                          -0.072,
                          0.009])

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.three_month_periods],
                         [-0.087,
                          0.003,
                          0.055,
                          -0.026,
                          -0.072,
                          -0.058,
                          -0.075,
                          -0.218,
                          -0.293,
                          -0.214])

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.six_month_periods],
                         [-0.110,
                          -0.069,
                          -0.006,
                          -0.099,
                          -0.274,
                          -0.334,
                          -0.273])

        self.assertEqual([round(x.benchmark_period_returns, 3)
                          for x in metrics.year_periods],
                         [-0.353])
开发者ID:aichi,项目名称:zipline,代码行数:47,代码来源:test_risk.py


示例15: test_treasury_returns

    def test_treasury_returns(self):
        returns = factory.create_returns_from_range(self.sim_params)
        metrics = risk.RiskReport(returns, self.sim_params,
                                  trading_calendar=self.trading_calendar,
                                  treasury_curves=self.env.treasury_curves,
                                  benchmark_returns=self.env.benchmark_returns)
        self.assertEqual([round(x.treasury_period_return, 4)
                          for x in metrics.month_periods],
                         [0.0037,
                          0.0034,
                          0.0039,
                          0.0038,
                          0.0040,
                          0.0037,
                          0.0043,
                          0.0043,
                          0.0038,
                          0.0044,
                          0.0043,
                          0.004])

        self.assertEqual([round(x.treasury_period_return, 4)
                          for x in metrics.three_month_periods],
                         [0.0114,
                          0.0116,
                          0.0122,
                          0.0125,
                          0.0129,
                          0.0127,
                          0.0123,
                          0.0128,
                          0.0125,
                          0.0127])
        self.assertEqual([round(x.treasury_period_return, 4)
                          for x in metrics.six_month_periods],
                         [0.0260,
                          0.0257,
                          0.0258,
                          0.0252,
                          0.0259,
                          0.0256,
                          0.0257])

        self.assertEqual([round(x.treasury_period_return, 4)
                          for x in metrics.year_periods],
                         [0.0500])
开发者ID:kitylam9,项目名称:zipline,代码行数:46,代码来源:test_risk_period.py


示例16: test_benchmark_volatility_08

    def test_benchmark_volatility_08(self):
        returns = factory.create_returns_from_range(self.trading_env08)
        metrics = risk.RiskReport(returns, self.trading_env08)
        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.month_periods],
                         [0.069,
                          0.056,
                          0.080,
                          0.049,
                          0.040,
                          0.052,
                          0.068,
                          0.055,
                          0.150,
                          0.230,
                          0.188,
                          0.137])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.three_month_periods],
                         [0.118,
                          0.108,
                          0.101,
                          0.083,
                          0.094,
                          0.102,
                          0.172,
                          0.277,
                          0.328,
                          0.323])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.six_month_periods],
                         [0.144,
                          0.143,
                          0.143,
                          0.190,
                          0.292,
                          0.342,
                          0.364])
        # TODO: ugly, but I can't get the rounded float to match.
        # maybe we need a different test that checks the
        # difference between the numbers
        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.year_periods],
                         [0.391])
开发者ID:aichi,项目名称:zipline,代码行数:46,代码来源:test_risk.py


示例17: test_treasury_returns_06

    def test_treasury_returns_06(self):
        returns = factory.create_returns_from_range(self.sim_params)
        metrics = risk.RiskReport(returns, self.sim_params, env=self.env)
        self.assertEqual(
            [round(x.treasury_period_return, 4) for x in metrics.month_periods],
            [0.0037, 0.0034, 0.0039, 0.0038, 0.0040, 0.0037, 0.0043, 0.0043, 0.0038, 0.0044, 0.0043, 0.004],
        )

        self.assertEqual(
            [round(x.treasury_period_return, 4) for x in metrics.three_month_periods],
            [0.0114, 0.0116, 0.0122, 0.0125, 0.0129, 0.0127, 0.0123, 0.0128, 0.0125, 0.0127],
        )
        self.assertEqual(
            [round(x.treasury_period_return, 4) for x in metrics.six_month_periods],
            [0.0260, 0.0257, 0.0258, 0.0252, 0.0259, 0.0256, 0.0257],
        )

        self.assertEqual([round(x.treasury_period_return, 4) for x in metrics.year_periods], [0.0500])
开发者ID:maartenb,项目名称:zipline,代码行数:18,代码来源:test_risk_period.py


示例18: test_benchmark_volatility_06

    def test_benchmark_volatility_06(self):
        returns = factory.create_returns_from_range(self.trading_env)
        metrics = risk.RiskReport(returns, self.trading_env)
        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.month_periods],
                         [0.031,
                          0.026,
                          0.024,
                          0.025,
                          0.037,
                          0.047,
                          0.039,
                          0.022,
                          0.022,
                          0.021,
                          0.025,
                          0.019])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.three_month_periods],
                         [0.047,
                          0.043,
                          0.050,
                          0.064,
                          0.070,
                          0.064,
                          0.049,
                          0.037,
                          0.039,
                          0.037])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.six_month_periods],
                         [0.079,
                          0.082,
                          0.081,
                          0.081,
                          0.08,
                          0.074,
                          0.061])

        self.assertEqual([round(x.benchmark_volatility, 3)
                          for x in metrics.year_periods],
                         [0.100])
开发者ID:aichi,项目名称:zipline,代码行数:44,代码来源:test_risk.py


示例19: test_benchmark_returns_06

 def test_benchmark_returns_06(self):
     returns = factory.create_returns_from_range(self.sim_params)
     metrics = risk.RiskReport(returns, self.sim_params)
     np.testing.assert_almost_equal(
         [x.benchmark_period_returns
          for x in metrics.month_periods],
         ANSWER_KEY.BENCHMARK_PERIOD_RETURNS['Monthly'])
     np.testing.assert_almost_equal(
         [x.benchmark_period_returns
          for x in metrics.three_month_periods],
         ANSWER_KEY.BENCHMARK_PERIOD_RETURNS['3-Month'])
     np.testing.assert_almost_equal(
         [x.benchmark_period_returns
          for x in metrics.six_month_periods],
         ANSWER_KEY.BENCHMARK_PERIOD_RETURNS['6-month'])
     np.testing.assert_almost_equal(
         [x.benchmark_period_returns
          for x in metrics.year_periods],
         ANSWER_KEY.BENCHMARK_PERIOD_RETURNS['year'])
开发者ID:AmbroiseKritz,项目名称:zipline,代码行数:19,代码来源:test_risk_period.py


示例20: test_benchmark_returns_06

 def test_benchmark_returns_06(self):
     returns = factory.create_returns_from_range(self.trading_env)
     metrics = risk.RiskReport(returns, self.trading_env)
     self.assertEqual([round(x.benchmark_period_returns, 4)
                       for x in metrics.month_periods],
                      [0.0255,
                       0.0004,
                       0.0110,
                       0.0057,
                       -0.0290,
                       0.0021,
                       0.0061,
                       0.0221,
                       0.0247,
                       0.0324,
                       0.0189,
                       0.0139])
     self.assertEqual([round(x.benchmark_period_returns, 4)
                       for x in metrics.three_month_periods],
                      [0.0372,
                       0.0171,
                       -0.0128,
                       -0.0214,
                       -0.0211,
                       0.0305,
                       0.0537,
                       0.0813,
                       0.0780,
                       0.0666])
     self.assertEqual([round(x.benchmark_period_returns, 4)
                       for x in metrics.six_month_periods],
                      [0.015,
                       -0.0043,
                       0.0173,
                       0.0311,
                       0.0586,
                       0.1108,
                       0.1239])
     self.assertEqual([round(x.benchmark_period_returns, 4)
                       for x in metrics.year_periods],
                      [0.1407])
开发者ID:aichi,项目名称:zipline,代码行数:41,代码来源:test_risk.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python factory.create_simulation_parameters函数代码示例发布时间:2022-05-26
下一篇:
Python factory.create_returns_from_list函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap