r-COMP226

COMP226: Slides 2.4 Limit order books Rahul Savani rahul.savani@liverpool.ac.uk Limit order book markets In academic work, often called Continuous Double Auctions Mechanism to match buyers and sellers Consists of two types of order Limit orders Market orders Limit order book Limit orders are matched and/or stored Market orders are matched against limit orders if possible Unmatched limit orders are stored in the order book Buy orders or bids are stored in the bid book Sell orders or asks/offers are stored in the ask book Example Price Vol. 104.5 45 103.0 2 102.0 12 101.5 10 100.5 4 99.0 32 92.0 22 91.5 1 Bids appear below asks Price is ascending Best bid is 100.5 Best ask is 101.5 Midprice 100.5 + 101.5 2 = 101 Bid-ask spread 101.5 100.5 = 1 Limit order book with order IDs Price Vol. ID 102.0 5 915 102.0 7 902 101.5 9 901 101.5 1 920 100.5 2 901 100.5 2 912 99.0 31 910 99.0 1 901 Market order: buy 14 Price Vol. 103.0 2 102.0 12 101.5 10 100.5 4 99.0 32 92.0 22 Average price paid 101.5 × 10 + 102 × 4 10 + 4 = 101.6429 Resulting limit order book: Price Vol. 103.0 2 102.0 8 100.5 4 99.0 32 92.0 22 Midprice: 101 -> 101.25 Spread: 1 -> 1.5 Tick sizes and bid-ask spreads Tick size: smallest increment in price that an equity, future, or other exchange-traded instrument can move by Tick sizes can be fixed (e.g. $0.01, which is common for US equities, or a fixed number of points like 0.25 for an equities futures index), or may vary according to the current price For heavily-traded instruments the bid-ask spread will often be equal to the tick size (“the spread is one tick”) Similarly, it is often argued that smaller bid-ask spreads indicate more efficient markets because a wide spread indicates uncertainty about the “real price” Buying versus selling Short selling (also known as shorting or going short) is the practice of selling securities or other financial instruments that are not currently owned, and subsequently repurchasing them (“covering”) In the event of an interim price decline, the short seller will profit, since the cost of (re)purchase will be less than the proceeds which were received upon the initial (short) sale Shorting is a prevalent practice in equities markets Note: in futures markets one is agreeing to delivery in the future and it is not necessary to borrow the underlying at the time the derivative contract is sold Limit orders versus market orders Limit orders guarantee price but not execution Market orders guarantee execution (almost always) but not price For market orders, slippage is an important consideration Market data Trading models are developed using historical market data. There are several granularities of market data: Time-based Bars, e.g., daily, 1-minute bars Tick data (tick stands for the change in prices due to a trade) Just trades Level 1: trades, best bid, best ask Level 2: trades, multiple price levels (e.g. 5) in the book Example of bid/ask data NQ.csv: “Index”,”Open”,”High”,”Low”,”Close”,”Volume”,”Bid”,”Offer”,”BidSize”,”OfferSize” 2010-12-14 02:32:00,2209.5,2209.75,2209.25,2209.75,78,2209.5,2209.75,8,107 2010-12-14 02:33:00,2209.5,2210,2209.5,2209.5,51,2209.25,2209.75,20,24 2010-12-14 02:34:00,2209.5,2209.5,2209.5,2209.5,1,2209.25,2209.5,16,4 2010-12-14 02:35:00,2209.25,2210.25,2209.25,2210.25,22,2210,2210.25,13,3 2010-12-14 02:36:00,2209.75,2210,2209.75,2210,31,2209.75,2210.25,47,25 2010-12-14 02:37:00,2210.25,2210.75,2210.25,2210.75,58,2210.5,2211,20,72 2010-12-14 02:38:00,2210.75,2211,2210.5,2210.5,36,2210.5,2210.75,12,5 Example of bid/ask data x <- read.csv(file="NQ.csv", header=TRUE, # not needed row.names=1, sep=',', # not needed stringsAsFactors=FALSE) library(xts) x <- as.xts(x) Using row.names=1 sets the date-times as the names of the rows This is necessary to make as.xts() work Example of bid-offer spread > head(x) Open High Low Close Volume Bid Offer 2010-12-14 02:32:00 2209.50 2209.75 2209.25 2209.75 78 2209.50 2209.75 2010-12-14 02:33:00 2209.50 2210.00 2209.50 2209.50 51 2209.25 2209.75 2010-12-14 02:34:00 2209.50 2209.50 2209.50 2209.50 1 2209.25 2209.50 2010-12-14 02:35:00 2209.25 2210.25 2209.25 2210.25 22 2210.00 2210.25 2010-12-14 02:36:00 2209.75 2210.00 2209.75 2210.00 31 2209.75 2210.25 2010-12-14 02:37:00 2210.25 2210.75 2210.25 2210.75 58 2210.50 2211.00 BidSize OfferSize 2010-12-14 02:32:00 8 107 2010-12-14 02:33:00 20 24 2010-12-14 02:34:00 16 4 2010-12-14 02:35:00 13 3 2010-12-14 02:36:00 47 25 2010-12-14 02:37:00 20 72 plot(x[,”Bid”]) Dec 14 02:32 Dec 17 01:00 Dec 20 01:00 Dec 23 01:00 Dec 27 01:00 Dec 30 01:00 22 00 22 10 22 20 22 30 x[, “Bid”] Example continued Date/Time-based subsetting: x <- x["2010-12-14",c("Bid","Offer","BidSize","OfferSize")] x <- x['T10:00:00/T12:00:00'] # use xts time-of-the-day subsetting plot.zoo(x, screens=c(1,1,2,2), col=c("red","blue","red","blue"), ylab=c("Bid/Offer","Bid/Offer size")) 22 12 22 14 Bi d/ As k pr ic e 10:00 10:30 11:00 11:30 12:00 Index 0 50 15 0 25 0 35 0 Bi d/ As k vo lu m e nasdaqQuotes