Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Getting the index of the very next bar of trading data ?

Hi,

I'm using Quantopian/Zipline to backtest a school project. My data frequency is daily so technically every bar should represent a trading date. Data is fed into Zipline algo as a Pandas Panel. Due to one of the contraints of weighting scheme I use, I need to know the exact next trading date (index of the very next bar to the current one) so that I can calculate exactly the days elapsed between today and tomorrow. What I've tried is using the trading calendar of the NYSE and use the next_session_label function to get the next trading date, like this.

from zipline.utils.calendars import get_calendar  
global trading_calendar_name  
trading_calendar_name = 'NYSE'  
trading_calendar = get_calendar(trading_calendar_name)

# During the trading logics :  
today = context.get_datetime('UTC').date()  
next_date = get_calendar(trading_calendar_name).next_session_label(today)  

This works quite well with the NYSE, however, when I try to use either 'LSE' or a simple custom trading calendar that trades only on working week days, some dates are missing from the final result. One particular example is the date September 3rd 2012. For the 'LSE' trading calendar this is considered a trading date, however, in the backtest result this date is omitted, and orders are filled instead on September 4th 2012 even though in my original data there exists a bar for September 3rd 2012. My question then, is whether there is a way to know exactly the next date that zipline/quantopian will use to fill orders and generate backtest results ?

Thanks.