Mariner Backtesting - Strategy.on_arca_imbalance()

ARCA Imbalance Event

(system method) Overview:

This method will be called whenever a NYSE Arca imbalance event occurs (from the arca book feed).

Interface:
 def on_arca_imbalance(self,
                      event,
                      md,
                      order,
                      service,
                      account):
    pass
Data Attributes for event:
Name Type Information
exchange string "P" exchange details
indicative_match_price float The price at which all matched shares would trade at the time the Auction is run.
indicative_match_volume integer The number of shares that would match at the indicative price if the Auction were run at that moment.
kind integer Event enum (1) representing the kind of event. *LIVE AND FORWARD ONLY*, represents the type of event (trade, quote, news, imbalance etc)
market_imbalance integer

The market imbalance volume. '+' shares indicates buy imbalance '-' shares indicates a sell imbalance.

The Market Order Imbalance is the imbalance of any remaining Market Orders (or Market-on-Close orders for the Closing Auction) that cannot execute in a Market Order or Closing Auction. Calculation of match size and indicative match price remain unchanged.

symbol string 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.
timestamp muts Timestamp of the event
total_imbalance integer The total imbalance volume. '+' shares indicates buy imbalance '-' shares indicates a sell imbalance. The Total Imbalance is the net imbalance of orders at the indicative match price for all orders eligible for the next upcoming Auction. This includes Market (or Market-on-Close) and Limit Orders. Display of match size and indicative match price remain unchanged. The number of shares of buy orders minus the number of shares of sell orders. A positive Total Imbalance means an excess of buy orders and a negative Total Imbalance means an excess of sell orders.
type string
  • "o" == Arca Open Imbalance (happens at 4:30 easten)
  • "O" == Arca Market Imbalance (just prior to official open, 9:30 eastern)
  • "C" == Close
  • "H" == halt or ipo
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_arca_imbalance() is called.

from cloudquant.interfaces import Strategy


class OnArcaImbalanceExample(Strategy):
    do_once = True

    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'SPY'

    def on_start(self, md, order, service, account):
        if self.__class__.do_once:
            print service.time_to_string(service.system_time, '%Y-%m-%d')
            self.__class__.do_once = False
        print self.symbol


    def on_arca_imbalance( self, event, md, order, service, account ):
        print '\nin on_arca_imbalance()\n\t%s\n' % service.time_to_string(service.system_time, '%H:%M:%S.%f')
        print 'event - ArcaImbalanceEvent\n'

        print ' event.exchange  -   ', event.exchange
        print ' event.indicative_match_price    -   ', event.indicative_match_price
        print ' event.indicative_match_volume   -   ', event.indicative_match_volume
        print ' event.market_imbalance  -   ', event.market_imbalance
        print ' event.symbol    -   ', event.symbol
        print ' event.timestamp -   ', event.timestamp
        print ' event.total_imbalance   -   ', event.total_imbalance
        print ' event.type  -   ', event.type

        service.terminate()

Console

2016-01-04
SPY

in on_arca_imbalance()
    15:00:00.016000

event - ArcaImbalanceEvent

    event.exchange  -   P
    event.indicative_match_price    -   199.580001831
    event.indicative_match_volume   -   832836
    event.market_imbalance  -   0
    event.symbol    -   SPY
    event.timestamp -   1451937600016000
    event.total_imbalance   -   1654
    event.type  -   C