zipline icon indicating copy to clipboard operation
zipline copied to clipboard

Calendar hardcoded to US stock market

Open willianpaixao opened this issue 6 years ago • 5 comments

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?

willianpaixao avatar Feb 27 '19 13:02 willianpaixao

@ssanderson @freddiev4 any feedback?

willianpaixao avatar Jan 29 '20 14:01 willianpaixao

what you have made to get it work? @willianpaixao

billmoling avatar Mar 20 '20 17:03 billmoling

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:

  1. Change line 161 to: metadata['exchange'] = os.environ.get('CSVDIR_EXCHANGE', 'XNYS')
  2. Remove line 227

llllllllll avatar Mar 20 '20 17:03 llllllllll

@llllllllll Thanks very much. It works.

billmoling avatar Mar 20 '20 19:03 billmoling

@llllllllll I've followed your suggestion then tested #2674 locally and it works.

willianpaixao avatar Nov 09 '20 15:11 willianpaixao