Zipline: set_benchmark() does not work for custom bundles

Created on 18 Sep 2017  路  4Comments  路  Source: quantopian/zipline

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: (Windows Version or $ uname --all)
  • Python Version: $ python --3.4
  • Python Bitness: $ python -c 'import math, sys;print(int(math.log(sys.maxsize + 1, 2) + 1))'
  • How did you install Zipline: 1.1.1 conda
  • Python packages: $ pip freeze or $ conda list

Now that you know a little about me, let me tell you about the issue I am
having:

Description of Issue

I try to set a custom benchmark using the custom_benchmark() commmand. I tried to first set a benchmark from the default (quantopian-quandl) and seems to work fine:
set_benchmark(symbol("AAPL"))

however when i now make a custom bundle and try to set the benchmark

    context.benchmark='iShares_MSCI_Europe_UCITS_ETF_Acc'
    set_benchmark(symbol(context.benchmark))

where the symbol iShares_MSCI_Europe_UCITS_ETF_Acc is in the data and i can trade it, i get:

image

  • What did you expect to happen?
  • What happened instead?

Here is how you can reproduce this issue on your machine:

Reproduction Steps

1.
2.
3.
...

What steps have you taken to resolve this already?

...

Anything else?

...

Sincerely,
$ whoami

Benchmark Data Bundle

Most helpful comment

This is a hack, but what I do is ignore the benchmark by changing benchmark.py

to

import pandas as pd
from trading_calendars import get_calendar

def get_benchmark_returns(symbol, first_date, last_date):
    cal = get_calendar('NYSE')
    dates = cal.sessions_in_range(first_date, last_date)
    data = pd.DataFrame(index=dates, columns=['Close'])
    return data.sort_index().pct_change(1).iloc[0:]

which just sets all benchmark returns to zero. This works on a custom bundle. This assumes the calendar for the bundle is NYSE.

All 4 comments

I am facing the same issue

I am facing the same issue either. isnt there any solution yet?

I am facing the same issue. If benchmark can be turned off, that is the best.

This is a hack, but what I do is ignore the benchmark by changing benchmark.py

to

import pandas as pd
from trading_calendars import get_calendar

def get_benchmark_returns(symbol, first_date, last_date):
    cal = get_calendar('NYSE')
    dates = cal.sessions_in_range(first_date, last_date)
    data = pd.DataFrame(index=dates, columns=['Close'])
    return data.sort_index().pct_change(1).iloc[0:]

which just sets all benchmark returns to zero. This works on a custom bundle. This assumes the calendar for the bundle is NYSE.

Was this page helpful?
0 / 5 - 0 ratings