Mariner Backtesting - Strategy.on_nasdaq_imbalance()

NASDAQ imbalance events

(system method) Overview:

This method will be called whenever a NASDAQ imbalance event occurs (from the totalview feed).

Interface:
 def on_nasdaq_imbalance(self,
                        event,
                        md,
                        order,
                        service,
                        account):
    pass
Data Attributes for event:
Name Type Information
exchange string "Q" exchange details
far_price float A hypothetical auction-clearing price for cross orders only.
imbalance_quantity integer The number of shares not paired at the Current Reference Price
kind integer Event enum (2) representing the kind of event. *LIVE AND FORWARD ONLY*, represents the type of event (trade, quote, news, imbalance etc)
near_price float A hypothetical auction-clearing price for cross orders as well as continuous orders (live orders in the book at the time of the calculation).
paired_quantity integer The total number of shares that are eligible to be matched at the Current Reference Price
price_variation_indicator string The absolute value of the % of deviation of the NEAR Indicative Clearing Price to the nearest Current Reference Price.
  • "L" = less than 1%
  • "1" = 1 to .99%
  • "2" = 2 to .99%
  • "3" = 3 to .99%
  • "4" = 4 to .99%
  • "5" = 5 to .99%
  • "6" = 6 to .99%
  • "7" = 7 to .99%
  • "8" = 8 to .99%
  • "9" = 9 to .99%
  • "A" = 10 to .99%
  • "B" = 20 to 20.99%
  • "C" = 30% or greater
reference_price float The price at which the NOII shares are being calculated.
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 Time of the imbalance event
type string
  • "O" == NASDAQ Opening Cross
  • "H" == cross for IPO and halted/paused securities
  • "C" == NASDAQ Closing Cross
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_nasdaq_imbalance() is called.

 from cloudquant.interfaces import Strategy


class OnNasdaqImbalanceExample(Strategy):
    do_once = True

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

    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_nasdaq_imbalance( self, event, md, order, service, account ):
        print '\nin on_nasdaq_imbalance()\n\t%s\n' % service.time_to_string(service.system_time, '%H:%M:%S.%f')
        print 'event - NasdaqImbalanceEvent\n'


        print ' event.exchange  -   ', event.exchange
        print ' event.far_price -   ', event.far_price
        print ' event.imbalance_quantity    -   ', event.imbalance_quantity
        print ' event.kind  -   ', event.kind
        print ' event.near_price    -   ', event.near_price
        print ' event.paired_quantity   -   ', event.paired_quantity
        print ' event.price_variation_indicator -   ', event.price_variation_indicator
        print ' event.reference_price   -   ', event.reference_price
        print ' event.symbol    -   ', event.symbol
        print ' event.timestamp -   ', event.timestamp
        print ' event.type  -   ', event.type

        service.terminate()

Console

2016-08-01
AAPL

in on_nasdaq_imbalance()
    09:28:00.098000

event - NasdaqImbalanceEvent

    event.exchange  -   Q
    event.far_price -   104.5
    event.imbalance_quantity    -   -174503
    event.kind  -   2
    event.near_price    -   104.5
    event.paired_quantity   -   377839
    event.price_variation_indicator -   L
    event.reference_price   -   104.63999939
    event.symbol    -   AAPL
    event.timestamp -   1470058080098000
    event.type  -   O