Mariner Backtesting - Imbalances md.nyse_imb

An interface to the NYSE Openbook imbalance data for the current symbol.

NYSE Openbook imbalance data available through the strategy.on_nyse_imbalance() event. 

Data Attributes:

Sample - Access data attribute

 md.nyse_imb.abs_price_diff_bid_ask
Name Type Special Information
SSR_filling_price float NaN

This field contains the SSR Filing Price. This price is the price at which Sell Short interest will be filed in the matching in the event a Sell Short Restriction is in effect for the security.

The SSR Filing price is based on the National Best Bid at 9:28am . This price remains static after the SSR Filing price has been determined.

abs_price_diff_bid_ask float NaN calculated:
abs(price_diff_bid_ask)
abs_price_diff_from_pc float 0 calculated:
if clearing_price > 0 and stat.prev_close > 0:
    return abs(stat.prev_close - clearing_price)
else:
    return float('NaN')
abs_price_diff_from_pc_percent_atr float NaN calculated:
if stat.atr > 0:
    return abs_price_diff_from_pc / stat.atr * 100
else:
    return float('NaN')
clearing_price float NaN

The indicative matching price, the price closest to Reference Price where imbalance is zero.

If a continuous book clearing price is not reached, it is defaulted to 0.

The Opening Clearing Price will begin publication at approximately 2 minutes (9.28am) and will continue to be published on with the next Opening Imbalance publication interval

closing_only_clearing_price float NaN The Closing Only Clearing Price is defined as the closing only interest where price closest to last sale where imbalance is zero.
condition_indicator string    
exchange string None
  • "N" - NYSE
  • "A" - NYSE Mkt (AMEX)
exchange details
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 it's initial imbalance side. Even numbers indicate it has flipped back
high_imbalance integer 0 The highest value for Imbalance Shares. '+' shares indicates buy imbalance '-' shares indicates a sell imbalance.
high_imbalance_time muts 0 Time of Imbalance Shares High.
imbalance_quantity integer 0 The total imbalance quantity at the reference price point. '+' shares indicates buy imbalance '-' shares indicates a sell imbalance.
is_regulatory boolean False This field defaults to false, and is set to True when declared as 'Regulatory' in the initial NYSE Imbalance broadcast (not to be confused to NYSE Continuous Feed)
last_flip_time muts 0 Time of the latest imbalance flip.
paired_quantity integer 0 This field contains the paired off quantity at the reference price point. Similar to Matched Shares from ARCA and NASDAQ.
price_diff_bid_ask float NaN calculated:
if clearing_price > 0:
    if imbalance_quantity  0 and clearing_price > L1.ask:
        return clearing_price - L1.ask
return float('NaN')
price_diff_from_last float NaN calculated:
clearing_price - L1.last
price_percent_diff_last float NaN calculated:
if L1.last > 0:
    return price_diff_from_last / L1.last * 100
else:
    return float('NaN')
price_percent_pc float NaN calculated:
if clearing_price > 0 and stat.prev_close > 0:
    return clearing_price / stat.prev_close * 100
else:
    return float('NaN')
reference_price float NaN The Imbalance reference price point.
regulatory_quantity integer 0 Initial imbalance shares: if the imbalance was a 'REGULATORY' imbalance, else 0. '+' shares indicates BUY imbalance '-' shares indicates a SELL imbalance.
shares_percent_primary_vol float NaN calculated:
if L1.primary_acc_volume > 0:
    return imbalance_quantity / L1.primary_acc_volume * 100
else:
    return float('NaN')
shares_percent_vol float NaN calculated:
if L1.acc_volume > 0:
    return imbalance_quantity / L1.acc_volume * 100
else:
    return float('NaN')
symbol string    
timestamp muts 0 Timestamp of the event
type string 0
  • "O" - Open
  • "H" - Halt/IPO
  • "C" - Close
Remarks:
  • There are two NYSE Imbalance feeds (NYSE Broadcast?, and NYSE Continuous)
    • Broadcast? is 15 minutes before the close. Broadcast sets the is_regulatory
    • Continuous feed - ?
  • Keep in mind, md.nyse_imb has is_regulatory while NYSEImbalanceEvent has condition_indicator.
  • is_regulatory maintains the state of the Broadcast? event. There is a possible race condition when the first message on the continuous feed call on_nyse_imbalance while set to is_regulatory is set to False. Immediately after, on_nyse_imbalance is called from the Broadcast? event which sets is_regulatory to True.
Working Example:

Print attributes of md.nyse_imb when on_nyse_imbalance() is called.

from cloudquant.interfaces import Strategy


class NyseImbalanceExample(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 == 'JNJ'

    def on_start(self, md, order, service, account):
        print self.symbol

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

        print '\n\nmd.nyse_imb\n'
        print ' md.nyse_imb.SSR_filling_price   -   ', md.nyse_imb.SSR_filling_price
        print ' md.nyse_imb.abs_price_diff_bid_ask  -   ', md.nyse_imb.abs_price_diff_bid_ask
        print ' md.nyse_imb.abs_price_diff_from_pc  -   ', md.nyse_imb.abs_price_diff_from_pc
        print ' md.nyse_imb.abs_price_diff_from_pc_percent_atr  -   ', md.nyse_imb.abs_price_diff_from_pc_percent_atr
        print ' md.nyse_imb.clearing_price  -   ', md.nyse_imb.clearing_price
        print ' md.nyse_imb.closing_only_clearing_price -   ', md.nyse_imb.closing_only_clearing_price
        print ' md.nyse_imb.exchange    -   ', md.nyse_imb.exchange
        print ' md.nyse_imb.flip_count  -   ', md.nyse_imb.flip_count
        print ' md.nyse_imb.high_imbalance  -   ', md.nyse_imb.high_imbalance
        print ' md.nyse_imb.high_imbalance_time -   ', md.nyse_imb.high_imbalance_time
        print ' md.nyse_imb.imbalance_quantity  -   ', md.nyse_imb.imbalance_quantity
        print ' md.nyse_imb.is_regulatory   -   ', md.nyse_imb.is_regulatory
        print ' md.nyse_imb.last_flip_time  -   ', md.nyse_imb.last_flip_time
        print ' md.nyse_imb.paired_quantity -   ', md.nyse_imb.paired_quantity
        print ' md.nyse_imb.price_diff_bid_ask  -   ', md.nyse_imb.price_diff_bid_ask
        print ' md.nyse_imb.price_diff_from_last    -   ', md.nyse_imb.price_diff_from_last
        print ' md.nyse_imb.price_percent_diff_last -   ', md.nyse_imb.price_percent_diff_last
        print ' md.nyse_imb.price_percent_pc    -   ', md.nyse_imb.price_percent_pc
        print ' md.nyse_imb.reference_price -   ', md.nyse_imb.reference_price
        print ' md.nyse_imb.regulatory_quantity -   ', md.nyse_imb.regulatory_quantity
        print ' md.nyse_imb.shares_percent_primary_vol  -   ', md.nyse_imb.shares_percent_primary_vol
        print ' md.nyse_imb.shares_percent_vol  -   ', md.nyse_imb.shares_percent_vol
        print ' md.nyse_imb.timestamp   -   ', md.nyse_imb.timestamp
        print ' md.nyse_imb.type    -   ', md.nyse_imb.type

        service.terminate()

Console

2016-08-01
JNJ

in on_nyse_imbalance
    09:28:00.040000

md.nyse_imb

    md.nyse_imb.SSR_filling_price   -   0.0
    md.nyse_imb.abs_price_diff_bid_ask  -   0.0599975585938
    md.nyse_imb.abs_price_diff_from_pc  -   0.0400009155273
    md.nyse_imb.abs_price_diff_from_pc_percent_atr  -   3.97821155234
    md.nyse_imb.clearing_price  -   0.0
    md.nyse_imb.closing_only_clearing_price -   0.0
    md.nyse_imb.exchange    -   N
    md.nyse_imb.flip_count  -   0
    md.nyse_imb.high_imbalance  -   -38100
    md.nyse_imb.high_imbalance_time -   1470055500013000
    md.nyse_imb.imbalance_quantity  -   -2500
    md.nyse_imb.is_regulatory   -   False
    md.nyse_imb.last_flip_time  -   0
    md.nyse_imb.paired_quantity -   89400
    md.nyse_imb.price_diff_bid_ask  -   0.0599975585938
    md.nyse_imb.price_diff_from_last    -   -0.0199966430664
    md.nyse_imb.price_percent_diff_last -   -0.0159653836858
    md.nyse_imb.price_percent_pc    -   99.9680580416
    md.nyse_imb.reference_price -   125.230003357
    md.nyse_imb.regulatory_quantity -   0
    md.nyse_imb.shares_percent_primary_vol  -   nan
    md.nyse_imb.shares_percent_vol  -   -1602.56410256
    md.nyse_imb.timestamp   -   1470058050004000
    md.nyse_imb.type    -   O