[zipline] Lookahead bias

My setup is I go through a minute candle dataset.

For each invocation of the handle_data() function the logical time is at the start of that minute. At least that’s what context.get_datetime() says.

It turns out the protocol.BarData.current() method looks a bit in the future by returning the corresponding high/low/close, which shouldn’t be actually known until the end of the minute.

For example this is the data fed to the algorithm:
image

And this is what BarData.current() yields:

context.get_datetime()=2021-01-01 00:00:00+00:00
price=28991.010000000002
last_traded=2021-01-01 00:00:00+00:00
open=28948.190000000002
high=28997.16
low=28935.3
close=28991.010000000002
volume=143

Also it could be worth mentioning the volume is floor()ed.

On a side note, I’m sorry for just reporting potential problems and not committing patches, but first I need to explore zipline a bit to see whether it would be of use to me. Otherwise, Mr. Jansen, thank you for the great book! :slight_smile:

OK, my bad here. :slight_smile: It looks like the solution is quite simple – the bundle data fed to Zipline should have the date field set to the CloseTime.

Thank you, you’re welcome!

1 Like