Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data.current(), order() don't work for compounded stock symbols #78

Open
VitalyErmilov opened this issue Nov 19, 2017 · 3 comments
Open

Comments

@VitalyErmilov
Copy link

VitalyErmilov commented Nov 19, 2017

Dear Zipline Maintainers,
I've found that the function data.current() doesn't work now for so called fuzzy symbols (symbols that consist of two parts), such as BRK B (Berkshire Hathaway B).

I think the problem is that the way fuzzy symbols are presented now in securities database is incompatible with interactive brokers' smart search. So when we try to get market data for a fuzzy symbol, smart search can't find the security for the symbol which results in the following error:

'No security definition is found for this request, error code 200'

I tried to find BRK B stock in Tws manually and the result was that Tws couldn't find the security when querying 'BRK.B' or 'BRK_B''. But It managed to find it when I typed in the search box 'BRK B' (with a space)
brk b

brk b

We need to reflect this in how zipline-live handles compounded tickers to query interactive brokers in a way it can understand them.

To reproduce the issue try to retrieve some data_current() information for the stock BRK_B

Sincerely,
Vitaly Ermilov

@VitalyErmilov
Copy link
Author

VitalyErmilov commented Nov 20, 2017

So, the аsset's field 'symbol' contаins now quаndl's database code which uses delimiter '_' for compounded tickers, while we should hаve а blаnk space instead.
Here is the link to ib knowledge bаse section concerning the issue :
https://ibkr.info/node/462

@VitalyErmilov VitalyErmilov changed the title data.current() does not work for compounded stock symbols data.current(), order() don't work for compounded stock symbols Nov 20, 2017
@tibkiss
Copy link

tibkiss commented Nov 25, 2017

Thanks for reporting this issue.

Generic way of solving this issue would be to replace underscore to space (in case of IB), here:
https://github.com/zipline-live/zipline/blob/master/zipline/gens/brokers/ib_broker.py#L640
Care should be taken to handle all the cases where contract.m_symbol is used, otherwise order & position status would be negative affected.

A less generic way would be to build up a zp-symbol to ib-symbol mapping table. This approach would only be preferred, if the generic underscore-to-space approach would not work out.
Example of zp-symbol to ib-symbol mapping could be taken from symbol_to_exchange mapping:
https://github.com/zipline-live/zipline/blob/master/zipline/gens/brokers/ib_broker.py#L58-L64

@VitalyErmilov : Is this enough guidance to start working on the fix?

@VitalyErmilov
Copy link
Author

@tibkiss I've made a workaround by replacing underscores to spaces on the stage of data ingestion by modifying quandl.py. This tells that replacement method does work .
The first thing I tried was to make it in ib_broker.py because it's a broker specific code. But It seems to me that I didn't handle all the cases, so I couldn't get the preferable approach working.
I will make another try to do this. Thank you for the guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants