Skip to content

National Best Bid and Offer

Query Source: adopted from here

Introduction

Market Identifier Code (MIC) is an international standard, which "specifies a universal method of identifying exchanges, trading platforms, regulated or non-regulated markets and trade reporting facilities as sources of prices and related information in order to facilitate automated processing" as quoted from its official site.

The U.S. Equities market has 13 lit exchanges and dozens of Alternative Trading Systems (ATSs), a.k.a. dark pools. Many buy side firms also operate their own non-ATS crossing systems.

Question

There might be multiple exchanges quoting at the National Best Bid and Offer (NBBO) price level at any given time. It is assumed that child orders are always placed at NBBO and can be placed to any lit exchanges. The below function simChildOrders simulates some BUY orders with execution destination (exDest). See the definition of FIX tag for exDest. It also has a column nbbExchanges, which shows the list of lit exchanges that are present at the best bid price level.

simChildOrders:{[nOrders]
    seed:-314159;
    openTime:`time$09:30;
    closeTime:`time$16:00;
    litVenues:`XNYS`ARCX`XCHI`XASE`XCIS`XNAS`XBOS`XPHL`BATS`BATY`EDGA`EDGX`IEXG;

    system "S ",string seed;
    submitTimes:asc closeTime&openTime+nOrders?390*60*1000;

    system "S ",string seed;
    exDest:nOrders?litVenues;

    system "S ",string seed;
    nExchanges:3+nOrders?(count litVenues)-3;
    system "S ",string seed;
    nbbVenues:{y?x}[litVenues;] each nExchanges;

    ([] time:submitTimes;side:`BUY;exDest:exDest;nbbVenues:nbbVenues)
  };

childOrders:simChildOrders[5000];

Find the number of orders which are placed to exchanges present at NBB (National Best Bid).

Answer

Use each both

Learn more about each or each both here.

exec sum in'[exDest;nbbVenues] from childOrders

Each applied to a binary value is also called each both and the infix form can be used.

exec sum exDest in' nbbVenues from childOrders

Use where and any

exec count i from childOrders where any each exDest=nbbVenues

Use list argument

Note that the anonymous function is unary and the parameter is a list.

exec sum {x[0] in x[1]} each flip (exDest;nbbVenues) from childOrders

Use operator apply .

The operator apply . applies a function to a list and use the individual list elements as the arguments to the function. This is very much similar to * operator to unpack argument list to function call in Python and the spread operator ... in JavaScript.

exec sum ({x in y}.) each flip (exDest;nbbVenues) from childOrders