zipline
zipline copied to clipboard
Calendar hardcoded to US stock market
Hi fellow maintainers,
I've been trying to ingest non-USA CSV bundles with Zipline, but it proved much harder than I calculated. Turns out that there are some hardcoded variables that bind the process to only NYSE and UTC data. Follow some lines I had to change in order to have a successful (without crashes) bundle ingestion:
https://github.com/quantopian/zipline/blob/05a6080eed951f80da3b6f7ee4962101884f328e/zipline/data/bundles/csvdir.py#L161 https://github.com/quantopian/zipline/blob/05a6080eed951f80da3b6f7ee4962101884f328e/zipline/data/bundles/csvdir.py#L227
When I tried to fix the values, I've got an error here:
File "zipline/data/bundles/csvdir.py", line 161, in csvdir_bundle
metadata['exchange'] = calendar_name
NameError: name 'calendar_name' is not defined
It looked weird but I didn't have time to follow up and debug it.
My current state is simply change the hardcoded values from 'NYSE' to 'BVMF' and it works. Any suggestions on how to fix it for the long term?
@ssanderson @freddiev4 any feedback?
what you have made to get it work? @willianpaixao
Instead of setting an exchange of CSVDIR
, we should have an environment variable that can be set at ingest time where users can set the calendar. Maybe something like CSVDIR_EXCHANGE=XNYS
or something. The string would need to be a name that trading_calendars
can parse. We can preserve the default calendar of XNYS
(which NYSE
is an alias of) if a user doesn't provide a value.
I think the code changes needed to make this work are:
- Change line 161 to:
metadata['exchange'] = os.environ.get('CSVDIR_EXCHANGE', 'XNYS')
- Remove line 227
@llllllllll Thanks very much. It works.
@llllllllll I've followed your suggestion then tested #2674 locally and it works.