Mariner Backtesting - NASDAQ Imbalances

nasdaq_imb

md. (object) Overview:

The nasdaq_imb object represents the last imbalance event received for a given symbol from NASDAQ. There are morning and afternoon imbalances. NASDAQ typically publishes an imbalances for every symbol (not just NASDAQ listed symbols).

Data Attributes:

Sample - Access data attribute

 md.nasdaq_imb.abs_price_diff_from_far
Name Type Special Information
abs_price_diff_from_far float NaN calculated:
abs(price_diff_from_far)
abs_price_diff_from_far_percent_atr float 0 calculated:
if stat.atr > 0:
    return abs_price_diff_from_far / stat.atr * 100
else:
    return float('NaN')
abs_price_diff_from_near float    
abs_price_diff_from_near_percent_atr float NaN calculated:
if stat.atr > 0:
    return abs_price_diff_from_near / stat.atr * 100
else:
    return float('NaN')
abs_price_diff_from_pc float 0 calculated:
if reference_price > 0 and stat.prev_close > 0:
    return abs(reference_price - stat.prev_close)
else:
    return float('NaN')
abs_price_diff_from_pc_percent_of_atr float 0 calculated:
if stat.atr > 0:
    return abs_price_diff_from_pc / stat.atr * 100
else:
    return float('NaN')
exchange string None "Q" exchange details
far_price float NaN A hypothetical auction-clearing price for cross orders only.
flip_count integer 0 Number of times an imbalance flips from buy to sell or sell to buy. If this number goes from 0 to 1, it is the first time it has flipped. Odd numbers indicate it has flipped away from its initial imbalance side.
high_imbalance float 0 The highest value for Imbalance Shares. '+' shares indicates buy imbalance '-' shares indicates a sell imbalance.
high_imbalance_time integer 0 Time of Imbalance Shares High.
imbalance_quantity integer 0 The number of shares not paired at the Current Reference Price
last_flip_time integer 0 Time of the latest imbalance flip.
near_price float NaN 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 0  
price_diff_from_far float NaN calculated:
if reference_price > 0 and far_price > 0:
    return reference_price - far_price
else:
    return float('NaN')
price_diff_from_near float NaN calculated:
if reference_price > 0 and near_price > 0:
    return reference_price - near_price
else:
    return float('NaN')
price_variation_indicator String None 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 NaN The price at which the NOII shares are being calculated.
symbol string    
timestamp muts 0 Time of the imbalance event
type string 0
  • "O" == NASDAQ Opening Cross
  • "H" == cross for IPO and halted/paused securities
  • "C" == NASDAQ Closing Cross
Working Example:

Print attributes of md.nasdaq_imb when on_nasdaq_imbalance() is called.

 from cloudquant.interfaces import Strategy


class NasdaqImbalanceExample(Strategy):

    @classmethod
    def on_strategy_start(cls, md, service, account):
        print service.time_to_string(service.system_time, '%Y-%m-%d')

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

    def on_start(self, md, order, service, account):
        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 '\n\nmd.nasdaq_imb\n'

        print ' md.nasdaq_imb.abs_price_diff_from_far   -   ', md.nasdaq_imb.abs_price_diff_from_far
        print ' md.nasdaq_imb.abs_price_diff_from_far_percent_atr   -   ', md.nasdaq_imb.abs_price_diff_from_far_percent_atr
        print ' md.nasdaq_imb.abs_price_diff_from_near  -   ', md.nasdaq_imb.abs_price_diff_from_near
        print ' md.nasdaq_imb.abs_price_diff_from_near_percent_atr  -   ', md.nasdaq_imb.abs_price_diff_from_near_percent_atr
        print ' md.nasdaq_imb.abs_price_diff_from_pc    -   ', md.nasdaq_imb.abs_price_diff_from_pc
        print ' md.nasdaq_imb.abs_price_diff_from_pc_percent_of_atr -   ', md.nasdaq_imb.abs_price_diff_from_pc_percent_of_atr
        print ' md.nasdaq_imb.exchange  -   ', md.nasdaq_imb.exchange
        print ' md.nasdaq_imb.far_price -   ', md.nasdaq_imb.far_price
        print ' md.nasdaq_imb.flip_count    -   ', md.nasdaq_imb.flip_count
        print ' md.nasdaq_imb.high_imbalance    -   ', md.nasdaq_imb.high_imbalance
        print ' md.nasdaq_imb.high_imbalance_time   -   ', md.nasdaq_imb.high_imbalance_time
        print ' md.nasdaq_imb.imbalance_quantity    -   ', md.nasdaq_imb.imbalance_quantity
        print ' md.nasdaq_imb.last_flip_time    -   ', md.nasdaq_imb.last_flip_time
        print ' md.nasdaq_imb.near_price    -   ', md.nasdaq_imb.near_price
        print ' md.nasdaq_imb.paired_quantity   -   ', md.nasdaq_imb.paired_quantity
        print ' md.nasdaq_imb.price_diff_from_far   -   ', md.nasdaq_imb.price_diff_from_far
        print ' md.nasdaq_imb.price_diff_from_near  -   ', md.nasdaq_imb.price_diff_from_near
        print ' md.nasdaq_imb.price_variation_indicator -   ', md.nasdaq_imb.price_variation_indicator
        print ' md.nasdaq_imb.reference_price   -   ', md.nasdaq_imb.reference_price
        print ' md.nasdaq_imb.timestamp -   ', md.nasdaq_imb.timestamp
        print ' md.nasdaq_imb.type  -   ', md.nasdaq_imb.type

        service.terminate()

Console

2016-08-01
AAPL

in on_nasdaq_imbalance
    09:28:00.098000

md.nasdaq_imb

    md.nasdaq_imb.abs_price_diff_from_far   -   0.139999389648
    md.nasdaq_imb.abs_price_diff_from_far_percent_atr   -   7.01224085041
    md.nasdaq_imb.abs_price_diff_from_near  -   0.139999389648
    md.nasdaq_imb.abs_price_diff_from_near_percent_atr  -   7.01224085041
    md.nasdaq_imb.abs_price_diff_from_pc    -   0.430000305176
    md.nasdaq_imb.abs_price_diff_from_pc_percent_of_atr -   21.5377060801
    md.nasdaq_imb.exchange  -   Q
    md.nasdaq_imb.far_price -   104.5
    md.nasdaq_imb.flip_count    -   0
    md.nasdaq_imb.high_imbalance    -   -174503
    md.nasdaq_imb.high_imbalance_time   -   1470058080098000
    md.nasdaq_imb.imbalance_quantity    -   -174503
    md.nasdaq_imb.last_flip_time    -   0
    md.nasdaq_imb.near_price    -   104.5
    md.nasdaq_imb.paired_quantity   -   377839
    md.nasdaq_imb.price_diff_from_far   -   0.139999389648
    md.nasdaq_imb.price_diff_from_near  -   0.139999389648
    md.nasdaq_imb.price_variation_indicator -   L
    md.nasdaq_imb.reference_price   -   104.63999939
    md.nasdaq_imb.timestamp -   1470058080098000
    md.nasdaq_imb.type  -   O