how would you estimate your order in the exchange order book? The order of order events and acks is not deterministic or guaranteed. How could you write an algo to estimate accurately your position in the order queue? Note that when we send an order to exchange, we get acknowledgement back from exchange, followed by market data add order event for our order. At the same time, we will receive order events for other orders. The order of these is not guaranteed. The goal is to estimate our position in the order queue.

  • 1
    $\begingroup$ besides all other complications it depends on the exchange $\endgroup$
    – LazyCat
    Jul 10 '12 at 21:51
  • $\begingroup$ the question is independent of the exchange. The order of messages is random. So we need to estimate our position in the book... $\endgroup$
    – Sam Hayen
    Jul 10 '12 at 23:04
  • 3
    $\begingroup$ You won't be able to determine your position in the book without knowing the particular rules of the exchange. It's not just first-come-first-serve vs pro-rata allocation. Some exchanges incentivize the market maker who sets the new inside price. There's also the possibility of routing instructions, hidden liquidity, and special members-only orders that jump the queue. $\endgroup$ Jul 10 '12 at 23:46
  • $\begingroup$ @chrisaycock why not make that an answer. $\endgroup$ Jul 11 '12 at 14:17
  • $\begingroup$ Hi Sam, welcome to quant.SE and thanks for posting your questions. $\endgroup$ Jul 11 '12 at 14:17

You have two ways to estimate your position in an order book:

  • first if you have access to an ITCH feed, you can recognize your order into the ITCH updates, and know exactly where you are, but you will have to build an engine to translate an order-by-order ITCH feed to a limit order book;
  • or you have to use estimates; the easiest way to build one is to follow this process:

    1. you are right on the fact that the synchronisation of the messages you have back from the market on your own orderbook and the feed describing the state of the market (the public orderbook) is often far from perfect. You can nevertheless build an estimate of the delay $\hat \delta$ between these two feeds. You can do this when you obtain a fill or partial fill, you know when you have it back via a direct message from the market (say, at time $t_1$) and when you can see it on the public feed (say, at time $t_2$), you know at such events that for your $n$th event like that $\delta(n)=t_2-t_1$. Any smoothing of the $\delta(n)$ (like a exponential moving average) can be used to obtain $\hat \delta$.
    2. when you insert an order of size $Q_i$ at price $P_i$ (or modify, but in general modifications are slower than inserts), just note the time of the acknowledge of it $t_i$ and look for an increate of the volume $Q_i$ at your price $P_i$ around $t_i+\hat\delta$: once it is done (say that you found it at time ${\hat t}_i$) you now have an estimate ${\hat V}_-(0)$ of the volume before you in the queue (by the way you aslo obtained one more $\delta(n)$ to adjust your $\hat\delta$). Of course you miss the hidden orders if any, but in general they will not disturb you that much:

      • the non-disclosed part icebergs do not have in general more priority than visible orders
      • fully hidden orders like instance LiS (Large in Scale) orders integrated in European Lit books have a different priority anyway
      • the only issue you will have is that some trading venues provide internalisation services, meaning that if a broker pay specific fees, he will be able to obtain a match between a sell market order and a buy limit orders he owns even if the buy order is not the first in the queue (you can see that as a cheap broker crossing service provided by the venue)
    3. now you just need to update the quantity $\hat V_-(0)$, that for you need to monitor the quantity ${\cal Q}$ on the queue of price $P_i$:

      • at ${\hat t}_i$, it was ${\cal Q}(0)=\hat V(0)+Q_i$
      • you will have to maintain a quantity $\hat V_+$, the quantity at the same price $P_i$ but with a lower priority than your order
      • let say that you just saw the $n$th event on ${\cal Q}$, which value is now ${\cal Q}(n)$, few milliseconds later you observe that now its value is ${\cal Q}(n+1)$

        • for an increase of the quantity: ${\cal Q}(n+1)>{\cal Q}(n)$, you have to assume that it has a lower rank in the queue than your order: increase $\hat V_+(n)$ by the increase: $$\hat V_+(n+1)=\hat V_+(n)+({\cal Q}(n+1) - {\cal Q}(n) )$$
        • for a decrease of the quantity: ${\cal Q}(n+1)<{\cal Q}(n)$, you have to make an assumption on the probability that is affects $\hat V_+$ rather than $\hat V_-$; you have three ways to do this, choose one ($[\cdot]_{-/+}$ means the negative or positive part): $$\Delta V = {\cal Q}(n) - {\cal Q}(n+1)$$
          1. a risk-averse version, put all that you can on $\hat V_+$ $$\left\{\begin{array}{lcl} \hat V_+(n+1)&=& [ \hat V_+(n)-\Delta V_+]_+\\ \hat V_-(n+1)&=& \hat V_-(n) + [ \hat V_+(n)-\Delta V_+]_- \end{array}\right.$$
          2. a neutral version: you first compute the probability that the decrease is on $\hat V_+$ or $\hat V_-$ according the their relative size: $$\mathbb{P}_+(n) =\frac{f(\hat V_+(n))}{f(\hat V_+(n))+f(\hat V_-(n))}$$ where $f$ is any increasing function (you can take the identity to make it simple): $$\left\{\begin{array}{lcl} \hat V_+(n+1)&=& [ \hat V_+(n)- \mathbb{P}_+(n) \Delta V_+]_+\\ \hat V_-(n+1)&=& \hat V_-(n) - (1-\mathbb{P}_+(n)) \Delta V_+ + [ \hat V_+(n)-\mathbb{P}_+(n) \Delta V_+]_- \end{array}\right.$$

        Of course from time to time you have have small inconsistencies, take some simple assumptions and adjust $\hat\delta$ when it is the case.

        Thanks to this procedure you will have an estimate of the quantity before you $\hat V_-$ and after you $\hat V_+$ at any time.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.