Skip to content

Quote Imbalance

image Source: adopted from here

Introduction

The order book quote imbalance is one of fundamental signals used to predict short-term price movement. The instantaneous quote imbalance can be calculated from the limit order book snapshot at any given time t. One of the definition can be:

\begin{alignedat}{3} weightedBidSize &= \frac{\sum_{i=1}^n \frac{bidSize_i}{midQuotePrice - bidPrice_i}}{\sum_{i=1}^n \frac{1}{midQuotePrice - bidPrice_i}} \\ weightedAskSize &= \frac{\sum_{i=1}^n \frac{askSize_i}{midQuotePrice - askPrice_i}}{\sum_{i=1}^n \frac{1}{midQuotePrice - askPrice_i}} \\ quoteImbl &= \frac{weightedBidSize - weightedAskSize}{weightedBidSize + weightedAskSize} \end{alignedat}

where midQuotePrice=\frac{bidPrice_1 + askPrice_1}{2}, bidPrice_i and bidSize_i are the i^{th}-level price and size on the bid side and askPrice_i and askSize_i are the i^{th}-level price and size on the ask side. The above definition uses the reciprocal of the distance from each price level to the mid-quote as the weight and calculates a weighted average of book pressure on bid and ask side.

Question

The function simLimitOrderBook simulates the limit order book of a few selected symbols in the continuous trading session from 09:30 to 16:00.

simLimitOrderBook:{
  n:10000;
  system "S -314159";
  syms:n?`AAPL`C`IBM;
  times:asc 09:30+n?"n"$06:30;
  bidPrices:20+0.01*sums?[n?1.<0.5;-1;1];
  bidSizes:n?10000;
  t:([] sym:syms;time:times;bidPrice1:bidPrices;bidSize1:bidSizes);
  t:update bidPrice2:bidPrice1-0.01*1+n?3,bidSize2:n?10000 from t;
  t:update bidPrice3:bidPrice2-0.01*1+n?3,bidSize3:n?10000 from t;
  t:update bidPrice4:bidPrice3-0.01*1+n?3,bidSize4:n?10000 from t;
  t:update bidPrice5:bidPrice4-0.01*1+n?3,bidSize5:n?10000 from t;

  t:update askPrice1:bidPrice1+0.01*1+n?6,askSize1:n?10000 from t;
  t:update askPrice2:askPrice1+0.01*1+n?3,askSize2:n?10000 from t;
  t:update askPrice3:askPrice2+0.01*1+n?3,askSize3:n?10000 from t;
  t:update askPrice4:askPrice3+0.01*1+n?3,askSize4:n?10000 from t;
  t:update askPrice5:askPrice4+0.01*1+n?3,askSize5:n?10000 from t;
  t
  };
lob:simLimitOrderBook[];

Implement a function calculateQuoteImbl[lob] to calculate the quote imbalance using the top 5 levels of the limit order book.

Answer

The suggested answer is as follows.

calculateQuoteImbl:{[lob]
  // Calculate the mid-quote price as the average of the best bid and best ask price
  lob:update midPx:0.5*bidPrice1+askPrice1 from lob;

  // Calculate the weighted average of bid size and ask size across all five price levels
  // Weights for each price level is the reciprocal of the distance between the mid-quote 
  // price and the current price level
  avgSize:select sym,time
      ,weightedBidSize:(1%midPx-bidPrice1;1%midPx-bidPrice2;1%midPx-bidPrice3;1%midPx-bidPrice4;1%midPx-bidPrice5) wavg (bidSize1;bidSize2;bidSize3;bidSize4;bidSize5)
      ,weightedAskSize:(1%askPrice1-midPx;1%askPrice2-midPx;1%askPrice3-midPx;1%askPrice4-midPx;1%askPrice5-midPx) wavg (askSize1;askSize2;askSize3;askSize4;askSize5)
    from lob;

  // The final quote imbalance is a value within [-1, 1]
  select sym,time,quoteImbl:(weightedBidSize-weightedAskSize)%weightedBidSize+weightedAskSize from avgSize
  };
calculateQuoteImbl[lob]