def date_gen(start, end, trading_calendar, delta=timedelta(minutes=1), repeats=None):
 daily_delta = (not (delta.total_seconds() % timedelta(days=1).total_seconds()))
 cur = start
 if daily_delta:
  cur = cur.replace(hour=0, minute=0, second=0, microsecond=0)
 def advance_current(cur):
  '\n        Advances the current dt skipping non market days and minutes.\n        '
  cur = (cur + delta)
  currently_executing = ((daily_delta and (cur in trading_calendar.all_sessions)) or trading_calendar.is_open_on_minute(cur))
  if currently_executing:
   return cur
  elif daily_delta:
   return trading_calendar.minute_to_session_label(cur)
  else:
   return trading_calendar.open_and_close_for_session(trading_calendar.minute_to_session_label(cur))[0]
 while (cur < end):
  if repeats:
   for j in range(repeats):
    (yield cur)
  else:
   (yield cur)
  cur = advance_current(cur)

def date_gen ( start , end , trading_calendar , delta = timedelta ( minutes = 1 ) , repeats = None ) : daily_delta = ( not ( delta . total_seconds ( ) % timedelta ( days = 1 ) . total_seconds ( ) ) ) cur = start if daily_delta : cur = cur . replace ( hour = 0 , minute = 0 , second = 0 , microsecond = 0 ) def advance_current ( cur ) : cur = ( cur + delta ) currently_executing = ( ( daily_delta and ( cur in trading_calendar . all_sessions ) ) or trading_calendar . is_open_on_minute ( cur ) ) if currently_executing : return cur elif daily_delta : return trading_calendar . minute_to_session_label ( cur ) else : return trading_calendar . open_and_close_for_session ( trading_calendar . minute_to_session_label ( cur ) ) [ 0 ] while ( cur < end ) : if repeats : for j in range ( repeats ) : ( yield cur ) else : ( yield cur ) cur = advance_current ( cur )
utility to generate a stream of dates .