Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Quick backtest scheduled function times seem wrong

I am trying to use the schedule_function function, but the reported time of the function execution seems wrong to me. Here's my example:

def initialize(context):  
  context.issues = [ symbol('AAPL') ]


  schedule_function(  
    func=testFunc,  
    date_rule=date_rules.every_day(),  
    time_rule=time_rules.market_open(),  
    half_days=False  
  )

  return


def testFunc( context, data ):  
  log.debug( get_datetime('US/Eastern') )


def handle_data(context, data):  
  log.debug('handle_data')  

When I build this algo, the first few lines of log output look like this:

2011-01-04handle_data:22DEBUGhandle_data  
2011-01-04testFunc:18DEBUG2011-01-03 19:00:00-05:00  
2011-01-05handle_data:22DEBUGhandle_data  
2011-01-05testFunc:18DEBUG2011-01-04 19:00:00-05:00  
2011-01-06handle_data:22DEBUGhandle_data  
2011-01-06testFunc:18DEBUG2011-01-05 19:00:00-05:00  
2011-01-07handle_data:22DEBUGhandle_data  
2011-01-07testFunc:18DEBUG2011-01-06 19:00:00-05:00  
2011-01-10handle_data:22DEBUGhandle_data  
2011-01-10testFunc:18DEBUG2011-01-09 19:00:00-05:00  
2011-01-11handle_data:22DEBUGhandle_data  
2011-01-11testFunc:18DEBUG2011-01-10 19:00:00-05:00  
2011-01-12handle_data:22DEBUGhandle_data  
2011-01-12testFunc:18DEBUG2011-01-11 19:00:00-05:00  
2011-01-13handle_data:22DEBUGhandle_data  
2011-01-13testFunc:18DEBUG2011-01-12 19:00:00-05:00  
2011-01-14handle_data:22DEBUGhandle_data  
2011-01-14testFunc:18DEBUG2011-01-13 19:00:00-05:00  
2011-01-18handle_data:22DEBUGhandle_data  
2011-01-18testFunc:18DEBUG2011-01-17 19:00:00-05:00  
2011-01-19handle_data:22DEBUGhandle_data  

Obviously I'm missing something basic here because according to get_datetime, the scheduled function is firing at 7pm EST, rather than at market open (about 9:30am EST). Any point in the right direction would be greatly appreciated.

1 response

Intraday scheduled functions don't run at specific times when you are doing a daily-mode backtest, you need to switch the backtest to minute-mode.