# Algorithm to detect the aggressor side of a trade

Most of the exchanges provide aggressor side property of trades (e.g. Tag=5797 AggressorSide on CME) in their raw data. But many data providers do not provide this information via their datafeed API's. I need an algorithm to estimate with high precision the trade's aggressor side.

public static int get_aggressor(int bid, int ask, int trade_price){
int aggr = Tags.UNKNOWN_SIDE;
if (bid < ask){ // i.e. no cross
} else if (trade_price <= bid){
aggr = Tags.SELL_SIDE;
}
}
return aggr;
}


where bid and ask are best bid/ask prices at a time when the trade was received. This algorithm may fail to detect the aggressor when the trade in the question affects the best bid/ask.

Question: Suppose I have the history of recent price updates. How to improve the precision of the aggressor detection algorithm? Also, consider two types of data feed:

2. The order of updates arrival in #1 is not guaranteed.

Please let me know if there are published researches on this topic.

-

The most commonly-known approach to this is described in Inferring trade direction from intraday data (1991) by Lee and Ready. You will find that the non-trivial part has to do with classifying trades that are reported inside the spread. I believe you will find that the Lee-Ready algorithm will outperform the naive midpoint reference approach suggested by @Svisstack, but nevertheless you will not be able to fully mitigate misclassification.

A more modern exposition of the criticisms of the Lee-Ready algorithm is given by Chakrabarty et al (2012), which should give you a starting point for other readings.

-
does this article provide an algorithm to determine aggressor side for each trade? (please note, i'm not looking for statistical estimation of daily percentage, etc.) –  Serg Aug 27 at 15:16
@Serg: Yes, that is what I understand you're looking for. –  madilyn Aug 27 at 15:55
Thank you, I will look into it –  Serg Aug 27 at 19:26

Most of these classifications of aggressive trades are not so relevant anymore, due to smart order routers which execute aggressive parent orders using passive child orders, as Maureen O'Hara points out in http://www2.warwick.ac.uk/fac/soc/wbs/subjects/finance/fof2014/programme/maureen_ohara.pdf

I am not sure what I would do if I wanted this information, but I suspect one will have to model the order book in order to get a real sense of whether liquidity is actually entering or leaving the market.

EDIT: Also, be very careful if you are trying to do this for equities using SIP data, since very often the quote feed and the trade feed are lagged with respect to each other, which will throw off any of the above classifications.

-
I'm only interested in futures, and only CME and Eurex. Note, that I subscribe also to the full order book data (as much as provider allows). I just thought that maybe if I use several recent changes in the best bid/ask (e.g. bid up, ask up, bid down, etc.), it could improve the precision of estimation. –  Serg Aug 28 at 20:17

I think spread midpoint will be more safe reference, after that if transaction price is higher from midpoint its buy, otherwise sell, if equal then not specified.

-