quantopian / zipline

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

STOXX 600 Equity Bundle help #2826

Open r54885ab opened 2 years ago

r54885ab commented 2 years ago

Hi there,

This is my first ever issue on GitHub so really sorry if my question is unclear or not in the appropriate format.

I am currently trying to build an equity bundle filled with the STOXX 600. Given this is a basket of European stocks, they all trade on different exchanges throughout Europe with different trading holidays and opening hours.

It appears to me that Zipline is very much geared towards equity bundles which contain stocks that all trade on the exact same exchange. Does anyone know how I might be able to ingest a bundle that does not follow only one trading calendar, but multiple?

What I have done so far:

I have followed the guide located here: https://analyzingalpha.com/zipline-equity-bundle

and with this guide, I have been able to utilize BColzDailyBarWriter() to write the stocks into a BColz format. In the below code, I am looping through my asset_metadata table, which contains information on each stock (i.e its associated exchange code like "XLON", its trading start date and trading end date, etc...), and then setting the calendar argument via the get_calendar() function.

for asset_sid, row in assets_metadata.iterrows():

    daily_bar_writer = BcolzDailyBarWriter(
        calendar=get_calendar(row['exchange']),  # Would love to default to LSE for everything
        start_session=pd.Timestamp("2010-01-04", tz='UTC'),
        end_session=pd.Timestamp("2021-07-29", tz='UTC'),
        filename=r'Stefan_Jansen/ch4/Pt_2_zipline_single_factor/bcolz_sxxp_data/bcolz_sxxp.bcolz'
    )

    daily_bar_writer.write(
        data = parse_pricing_and_vol(
            raw_data,
            asset_sid,
            row['symbol'],
            row['sessions']
        ),
        show_progress=True
    )

But when I get to the register() step, the function is forcing me to select a single calendar (via the register() argument, calendar_name) and so I am a bit stumped because all my stocks must then follow the trading days of that one calendar. Should I write a new register() function for every exchange and its associated stocks?

from zipline.data.bundles import register, sxxp_bundle

register('sxxp_bundle', sxxp_bundle.ingest, calendar_name='????')

Any help on this issue would be a huge godsend! Thank you all.

beglitis commented 1 year ago

Hi there, did you ever figure out the answer on this one?