quantopian / zipline

Zipline, a Pythonic Algorithmic Trading Library
https://www.zipline.io
Apache License 2.0
17.68k stars 4.73k forks source link

set_benchmark() does not work for custom bundles #1951

Open ikfdarba opened 7 years ago

ikfdarba commented 7 years ago

Dear Zipline Maintainers,

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

Environment

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

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

dawgster commented 6 years ago

I am facing the same issue

acanacar commented 6 years ago

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

imkoukou commented 6 years ago

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

marketneutral commented 6 years ago

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.