zipline
zipline copied to clipboard
Current price same for before_market_start and handle_data (daily data)
Hello, when running zipline with daily data, price (plus open/close/high/low/last transaction/volume) is the same for:
before_market_start handle_data
and any function I schedule using time/date rules. I would expect at least to get the previous day's price in before_market_start. It would be nice to get that day's open if calling a schedule function at market open and price close with a schedule function at market close.
Use case would be select security base on previous day's price in before_market_start. Order security at open and check price at close.
In daily mode, any function run with schedule_function is essentially equivalent to just running the same code in handle_data. This is part of the reason that we've actually droppped support for daily mode entirely on Quantopian: too many users found the behavior of schedule_function confusing in daily mode. The right fix for this is probably to just raise a DeprecationWarning if schedule function is used in daily mode. cc @llllllllll @jbredeche for thoughts on this.
As for getting the same data in before_trading_start and handle_data, that sounds like a bug to me. before_trading_start should conceptually run before the first bar of the day, while handle_data should run conceptually on the last bar of the day in daily mode, so I'd expect to see the previous day's OHLCV in before_trading_start.
Thanks for the reply. I am intending to use zipline for development and then load code into quantopian, so it would be good for zipline code to match quantopian as much as possible.
Using schedule_function and explicitly stating an open or close price is easy enough. A note about the limitations of using daily mode in the zipline docs would be helpful.
Agree that before_trading_start conceptually should return prior days prices. Current price could be 'Nan'.
Can I work on this issue?