Mariner Backtesting - Strategy.on_minute_bar()

Minute Bar event

This method will be called every minute before the first on_trade of every new minute, or 5 seconds after a new minute starts. It will allow you to perform logic with minute bars more efficiently in here, then on_trade()

Interface:
 def on_minute_bar(self,
                  event,
                  md,
                  order,
                  service,
                  account,
                  bar):
    pass
Data Attributes for event:
Name Type Special Information
askvol integer 0 The symbol's ask volume for this minute. If the symbol had no activity over the last minute, this will be 0.
bidvol integer 0 The symbol's bid volume for this minute. If the symbol had no activity over the last minute, this will be 0.
close float NaN The symbol's closing price for this minute. If the symbol had no activity over the last minute, this will be NaN (i.e. the IEEE 'not-a-number').
count integer 0 The symbol's count for this minute. If the symbol had no activity over the last minute, this will be 0.
high float NaN The symbol's highest price for this minute. If the symbol had no activity over the last minute, this will be NaN (i.e. the IEEE 'not-a-number').
length integer 60 The number of seconds that this bar was formed over. For minute bars, this should always be 60.
low float NaN The symbol's lowest price for this minute. If the symbol had no activity over the last minute, this will be NaN (i.e. the IEEE 'not-a-number').
open float NaN The symbol's opening price for this minute. If the symbol had no activity over the last minute, this will be NaN (i.e. the IEEE 'not-a-number').
spread float NaN The symbol's spread for this minute. If the symbol had no activity over the last minute, this will be NaN (i.e. the IEEE 'not-a-number').
symbol string    
timestamp muts    
volume integer 0 The symbol's aggregate volume for this minute. If the symbol had no activity over the last minute, this will be 0.
vwap float NaN The symbol's vwap for this minute. If the symbol had no activity over the last minute, this will be NaN (i.e. the IEEE 'not-a-number').
Remarks:
  • Event Symbol. In most cases symbol is obvious (self.symbol, md.symbol). If the script has subscribed to multiple symbols events, then event.symbol should be used to identify the symbol.
Working Example:

Print the attributes of event when on_minute_bar() is called.

 from cloudquant.interfaces import Strategy

class OnMinuteBarExample(Strategy):

    # note that this doesn't start with "self" because it's a @staticmethod
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'AAL'


    # called at the beginning of each instance
    def on_start(self, md, order, service, account):
        pass

    def on_minute_bar(self, event, md, order, service, account, bar):

        print 'timestamp:\t%s\nsymbol:\t%s\nlength:\t%s\nopen:\t%s\nhigh:\t%s\nlow:\t%s\nclose:\t%s\nvolume:' \
            '\t%s\nvwap:\t%s\nspread:\t%s\nbidvol:\t%s\naskvol:\t%s\ncount:\t%s' % \
            (event.timestamp, event.symbol, event.length, event.open, event.high, event.low, event.close,
            event.volume, event.vwap, event.spread, event.bidvol, event.askvol, event.count)
        service.terminate()

Console

timestamp:  1478007000000000
symbol: AAL
length: 60
open:   40.5099983215
high:   40.6399993896
low:    40.5
close:  40.6142997742
volume: 65005
vwap:   40.5316772461
spread: 0.0484388917685
bidvol: 47234
askvol: 4941
count:  145