【问题标题】:Zipline Bundle yesterday's dataZipline Bundle 昨天的数据
【发布时间】:2016-12-10 20:19:42
【问题描述】:

我正在通过将以下内容添加到 $ZIPLINE_ROOT 目录中的 extenstion.py 来创建一个自定义的基本 yahoo 包:

equities = {
    'AAPL',
    'QQQ',
}
register(
    'test-bundle',  # name this whatever you like
    yahoo_equities(equities),
)

当我运行捆绑包时,一切都很好。

zipline ingest -b test-bundle

zipline bundles

产生输出(我刚刚运行它一秒钟)

test-bundle 2016-12-10 20:13:11.014192

很好,一切都按预期进行。

当我使用一些基本策略运行 zipline 2 周时:

 zipline run -f ./test_algo.py --start 2016-12-01 --end 2016-12-9 -o output.pickle --bundle test-bundle

它运行,直到它到达星期四 (12/08/2016) 日期:

 Traceback (most recent call last):
 File "/usr/local/lib64/python3.5/site-packages/pandas/core/indexing.py", line 1325, in _has_valid_type error()
 File "/usr/local/lib64/python3.5/site-packages/pandas/core/indexing.py", line 1320, in error (key, self.obj._get_axis_name(axis)))
  KeyError: 'the label [2016-12-08 00:00:00+00:00] is not in the [index]'

  During handling of the above exception, another exception occurred:
  .... zipline stack trace

但如果我运行它:

 zipline run -f ./test_algo.py --start 2016-12-01 --end 2016-12-7 -o output.pickle --bundle test-bundle

然后我得到预期的成功输出:

 [2016-12-10 20:17:11.519059] INFO: Performance: Simulated 5 trading days out of 5.
 [2016-12-10 20:17:11.519495] INFO: Performance: first open: 2016-12-01 14:31:00+00:00
 [2016-12-10 20:17:11.519770] INFO: Performance: last close: 2016-12-07 21:00:00+00:00

知道为什么我的包会下载到 T-2 数据。我希望看到 12/8 和 12/9 的数据,市场在正常日子开放,我在 yahoo Finance 中看到了那些日子的数据。

谢谢-

【问题讨论】:

    标签: python python-3.5 quantitative-finance zipline


    【解决方案1】:

    这是因为基准回报不可用,只能从 T-2 基础上获得,包括交易日。 (即:如果您在星期一早上运行它,那么星期四的数据将可用,并且您可以在星期五之前运行模拟)如果您在星期六/星期日运行它,基准测试的最后一天是星期三,而最近的模拟日是星期四。

    可能的解决方案:

    1. 修改 Zipline 以关闭基准测试
    2. 修改 Zipline 以使用捆绑包中的任何代码作为基准(并且仅使用默认股票指数)

    当前解决方法:

    修改:./zipline/gens/tradesimulation.py

    并设置:

     def handle_benchmark(date, benchmark_source=self.benchmark_source):
         algo.perf_tracker.all_benchmark_returns[date] = 1
    

    这样它不会检查是否有数据,并且总是返回 1 作为基准

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多