Writing2012
Order Book Based HFT Trading for NSE India
Introduction
Classic asset pricing theory assumes prices will eventually adjust to and reflect the fair value,the route and speed of transition is not specified. Market Microstructure studies how prices adjust to reflect new information. Recent years have seen the widely available high frequency data enabled by the rapid advance in information technology. Using high frequency data, it’s interesting to study the roles played by the informed traders and noise traders and how the prices are adjusted to reflect information flow. It’s also interesting to study whether returns are more predictable in the high frequency setting and whether one could exploit limit order book dynamics in HFT trading.Broadly speaking, the traditional approach to statistical arbitrage is through attempting to bet on the temporal convergence and divergence of price movements of pairs and baskets of assets, using statistical methods. A more academic definition of statistical arbitrage is to spread the risk among thousands to millions of trades in very short holding time, hoping to gain profit in expectation through the law of large numbers. Following this line, recently,a model based approach has been proposed by Rama Cont and coauthors, based on a simple birth-death markov chain model. After the model is calibrated to the order book data, various types of odds can be computed. For example, if a trader could estimate the probability of mid-price uptick movement conditional on the current orderbook status and if the odds are in his/her favor, the trader could submit an order to capitalize the odds. When the trade is carefully executed with a judicious stop-loss, the trader should be able to make profit in expectation.
In this project, we adopted a data-driven approach. We first built an “simulated” exchange order matching engine which allows us to reconstruct the orderbook. Therefore, in theory, we’ve built an exchange system which allows us to not only back-test our trading strategies but also evaluate the price impacts of trading. And we then implemented, calibrated and tested the Rama Cont model on both simulated data and real data. We also implemented, calibrated and tested an extended model. Based on these models and based on the orderbook dynamics, we explored a few high frequency trading strategies.
In Section 2, we discuss the “simulated” exchange order matching engine. In Section 3, we present a few statistical observations and stylized facts about data. In Section 4, we review the Rama Cont model of order book dynamics and extend the Rama Cont model. In Section 5, we present the results of our trading strategy experiments and finally, Section 6 concludes the report.
Understand HFT Raw Data and Our Order Matching Engine (For any exchange Raw data – Real time or historical, contact Lokesh Madan) The data we have on hand are about 10 days of selected stocks, e.g. SBI, RIL, etc., from March 9, 2009 to March 20, 2009, from about 10:00am to 2:00pm everyday.
Each data file comes in the format of CSV and contains millions to tens of millions of lines. The following is a snippet.
All the fields are quite self-explanatory, where “bp”, “bs”, “ap” and “as” denote the bid price, bid size, ask price, and ask size, respectively.
To interpret the data, we made the following assumptions:
-
These are authentic Level 2 order arrival data in the raw message format. They are not the Level 1 data entailing best bids and best asks.
-
These are continuous streaming data, instead of snapshots sampled at fixed intervals.
-
These are raw data at the atomic level, therefore there are only three types of orders that are relevant: Market Orders, Limit Orders and Cancellation Orders. At higher investor levels, there are more fancy orders such as the stop-loss, stop-limit-loss, good- till-cancel orders, etc.
-
Market Orders are defined to be orders that are immediately transacted.
-
Limit Orders are defined to be orders that are not immediately transacted, therefore consumes liquidity.
6)The message with commas defines the cancelation order. Two commas on the bid side cancel the previous bid quote. The two numbers on the ask side are the new arrival of quotes. The four-comma rows are cancelation orders on both sides.
7)Cancelation order should cancel the previous orders from the same market maker, if that order was not filled; if the previous order was already filled, then the cancellation order is not effective and should be considered as void.
- When there are consecutive cancelation orders, we will recursively cancel the previous orders from the same market maker, one by one, in back order of time, unless the order-to-be-canceled has already been filled, in which case the corresponding cancellation order is considered as void and ineffective.
9)Time Precedence: Orders arrive earlier have priority.
10)Order Type Precedence: Market Order º Limit Order º Cancelation Order.
11)The messages are mostly in order of arrival time. However we did observe out-of-order messages. In that case, we just assume that the data-reporting facility had made errors and we correct the errors by re-ordering the messages in order of time by using stable sort.
-
Each message contains orders from both the bid and ask sides, this is because the market makers want to save bandwidth. In the cancellation message, one pair of commas are often bundled with limit or market orders from the opposite side. Again,our reasoning is that the market makers don’t want send one message for each single order, and their liquidity is sufficient so that they could pool orders from both sides into one single message.
-
We don’t discard the line with commas because we think with the advance of electronic trading, the cancellation orders should consume a significant fraction of the overall orders. The cancellation orders at the atomic level come from the modification orders at the high level, which are very common in electronic trading.
-
When executing a trade, the market order is first matched with the best opposite quote, and then the residue is matched with the second best opposite quote, so on and so forth.
-
The data file is self-contained so we don’t need any extra information such as times & sales data. Indeed, the data in this format actually contains much more information than the typical Level 2 data.
-
The last trade price is defined by the execution of market orders. If a large market order is matched to multiple price levels of the opposite best quotes, the last trade price is recorded accordingly.
To reconstruct the order book dynamics, we built an order matching engine, which does the following (For any Kind of simulation environment, contact Lokesh Madan)
-
For each message, classify the bid order into market order, limit order and cancellation order, and do the same for the ask side.
-
For market order, we just fill it immediately.
-
For limit order, we just insert them into the orderbooks.
-
For cancellation order, we search the separately maintained market-maker book and look for previous orders from the same market maker that are not yet filled. If that particular order has been already filled, we have to ignore the cancellation order. This reflects the fact that a trader might not be fast enough when he regrets about a previously submitted trade.
-
Update the last trade price and other times & sales trade statistics.
-
For later study of trading strategies, our order matching engine allows us, to submit our own orders and quotes, in an arbitrary manner,and all the orders will be interleaved and interact with each other.Therefore, in theory, we’ve built an exchange system which allows us to not only back-test our trading strategies but also evaluate the price impacts of trading.
Based on our order matching rules, we’ve reconstructed the orderbook for real data.
Using SBI on March 09, 2009 as an example, we have recorded from our data, the executed trade to be 96513473 shares, whereas Yahoo Finance record 87044700 shares. The difference could arise from the difference in trade accounting rules. Our results show a reasonable first order approximation to the order matching algorithm that are used by the NSE exchange.
In Rama Cont paper, using the parameters estimated by the authors, we could derive,as a first order approximation, the ratio of the cancellation orders to the total number of orders. The ratio is calculated to be about 33%. Using the Monte Carlo simulation, which is discussed later, we estimated the ratio to be about 40%. Using real data, for SBI on March 09, 2009, our order matching engine had recorded about 20% cancellation ratio. These numbers are roughly on par with each other, which provides some sanity check. We also observe that the estimated parameters in Rama Cont’s paper overestimated the ratio of cancellation orders, which does not reflect the feature of our data.
Remark: We’ve also done extensive research on the level 1 data and compared with our Raw NSE data TBT Data. While Level 1 data are popularly used in the market microstructure field, they are inferior to our data. The most important drawbacks are (1) Level 1 data are only precise up to 1 second. (2) Level 1 data with only best bid and best ask. (3) Level 1 data doesn’t have trade directions and researchers commonly have to resort to Lee & Ready algorithm which provides only about 80% accuracy in trade classification. Therefore we’ve decided to focus on the NSE RAW TBT data.
For more detail download
http://www.4shared.com/document/x1H8OHWl/Limit\_Order\_Book\_Based\_HFT\_Tra.html
Password – 1234
** Rgds Lokesh Madan Skype – lokesh.madan3 **
Responses 1
Archived · closed
-
Smith Kim June 9, 2012
Very interesting. I try to develop HFT platform. And the idea of your matching engine is impressive. Thanks.
Then.. I try to download your file. but your password is not valid.(^^;)