Empty Minute Bars - Thin symbols

ptunneyptunney Posts: 246
edited October 2018 in Quick Question

A question was asked about how get a minute bar for a thin symbol that is not empty...

There are three main options for Minute Bars...

  • today_only = True/False
  • include_extended = True/False
  • include_empty = True/False

If we set today_only = False and included_extended = True then that lets us pull ALL potential minute bars.

We will then just pull the last minute bar, what you get back depends how you set include_empty...

  • include_empty = True - you may get a NaN back, The easiest way to check for a NaN is to check "variable != variable" if that is True, it's a NaN.
  • include_empty = False - the bar that you get back could be very old, how old? Subtract the bar timestamp from the current (event) timestamp.
# Thin Symbols, Pulling a single Minute bar.
# For VVPR, try running on 10/22/2018 from 9am to 10am
# With the code in this script you can find out :
# For include_empty = False, how old the most recent minute bar is
# For include_empty = True, if the data in the bar is a Nan using the python check Variable!=Variable which surprisingly for a Nan returns True!


from cloudquant.interfaces import Strategy

class ThinMinuteBars(Strategy):

    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
#        return symbol =="IGA" # Very Thin ETF Symbol only trades market hours
        return symbol =="VVPR" # Very Thin Normal Symbol trades all hours

    def on_minute_bar(self, event, md, order, service, account, bar):
        myminbar = md.bar.minute(start=-1, today_only=False, include_extended=True, include_empty=True) 
        print "Include Empty       {}  timestamp of most recent bar {}    mins since last Market bar {:5}   Close price of most recent bar {:8.2f}  is that a Nan? {}".format(service.time_to_string(event.timestamp,"%Y-%m-%d %H:%M:%S"),service.time_to_string(myminbar.timestamp[-1],"%Y-%m-%d %H:%M:%S"), int((event.timestamp-myminbar.timestamp[-1])/60000000), myminbar.close[-1],myminbar.close[-1]!=myminbar.close[-1] )
        myminbar = md.bar.minute(start=-1, today_only=False, include_extended=True, include_empty=False) 
        print "Don't Include Empty {}  timestamp of most recent bar {}    mins since last Market bar {:5}   Close price of most recent bar {:8.2f}  is that a Nan? {}".format(service.time_to_string(event.timestamp,"%Y-%m-%d %H:%M:%S"),service.time_to_string(myminbar.timestamp[-1],"%Y-%m-%d %H:%M:%S"), int((event.timestamp-myminbar.timestamp[-1])/60000000), myminbar.close[-1],myminbar.close[-1]!=myminbar.close[-1] )
Sign In or Register to comment.