multithreading - Modelling Price-Time priority using OrderBook Data in R -


this question data structures , overall approaches difficult data wrangling problem tackle in r. if i've learnt here, there's nice solutions difficult problems advice appreciated

i have orderbook data stock exchange , i'm trying rebuild price-time priority queue @ time it. eg. there queue wants trade: buyer (or seller) highest bid (or lowest sellprice) should first buy (sell) when else comes along trade them. if there more 1 person offering same price, person declared intention buy (or sell) earlier @ front of queue. gets little messy because can change price , volume of order after you've sent order in. if increase volume of order should lose place in queue (but not if decrease volume of order). in practice, queue can change around lot , i'd accurately know @ front of queue of buyers (and same sellers) through day, @ time might need at.

here example of data working with:

library(data.table)  set.seed(1) unique.ids <- c("b-aaa","b-aab","b-aac","a-aaa","a-aab", "a-aac") seconds.since.midnight <- sort(sample(40000:40010, 12, replace = true)) order.type <- c("enter", "amend", "delete", "trade")  dt <- data.table(order = 1:12,                  time.scnds = seconds.since.midnight,                  type = order.type[c(1,1,1,1,2,4,                                      1,2,2,4,3,                                      1)],                  bid.id = na,                  ask.id = na,                  price = c(3.0,3.5, 3.3, 3.8,3.9,3.8, 3.8, 3.95, 3.8, 3.8,na, 4.1),                   volume = c(50,50,60,100,60,60,200,40,50,50,na, 100),                  oldprice = c(na,na,na,na,3.3,na,na,3.8,3.0,na,na,na),                  oldvolume = c(na, na,na,na,60,na,na,40,50,na,na,na))   dt$bid.id[c(1,2,3,5,6,9,10)] <- unique.ids[c(1,2,3,3,3,1,1)] dt$ask.id[c(4,6,7,8,10,11,12)] <- unique.ids[c(4,4,5,4,5,5,6)] dt      order time.scnds   type bid.id ask.id price volume oldprice oldvolume  1:     1      40000  enter  b-aaa     na  3.00     50       na        na  2:     2      40001  enter  b-aab     na  3.50     50       na        na  3:     3      40002  enter  b-aac     na  3.30     60       na        na  4:     4      40002  enter     na  a-aaa  3.80    100       na        na  5:     5      40002  amend  b-aac     na  3.90     60      3.3        60  6:     6      40004  trade  b-aac  a-aaa  3.80     60       na        na  7:     7      40006  enter     na  a-aab  3.80    200       na        na  8:     8      40006  amend     na  a-aaa  3.95     40      3.8        40  9:     9      40007  amend  b-aaa     na  3.80     50      3.0        50 10:    10      40009  trade  b-aaa  a-aab  3.80     50       na        na 11:    11      40009 delete     na  a-aab    na     na       na        na 12:    12      40010  enter     na  a-aac  4.10    100       na        na 

as orders enter, amend, trade, , deleted order in queue changes. end queue buyers , queue sellers. don't know best data structure be, if list might example:

buyers.queue [[1]] [1] "b-aaa"  [[2]] [1] "b-aab" "b-aaa"  [[3]] [1] "b-aab" "b-aac" "b-aaa"  [[4]] [1] "b-aab" "b-aac" "b-aaa"  [[5]] [1] "b-aac" "b-aab" "b-aaa"  [[6]] [1] "b-aac" "b-aab" "b-aaa"  [[7]] [1] "b-aab" "b-aaa"  [[8]] [1] "b-aab" "b-aaa"  [[9]] [1] "b-aaa" "b-aab"  [[10]] [1] "b-aaa" "b-aab"  [[11]] [1] "b-aab"  [[12]] [1] "b-aab" 

so each element of list (it has length 12) queue @ row of dt , queue ordered best price (in case, best price offered different bids, , time since arrival/recent amendment). notice how order can change around lot.

for sellers have (if in list- doesn't have be):

sellers.queue  [[1]] [1] na  [[2]] [1] na  [[3]] [1] na  [[4]] [1] "a-aaa"  [[5]] [1] "a-aaa"  [[6]] [1] "a-aaa"  [[7]] [1] "a-aaa" "a-aab"  [[8]] [1] "a-aab" "a-aaa"  [[9]] [1] "a-aab" "a-aaa"  [[10]] [1] "a-aab" "a-aaa"  [[11]] [1] "a-aaa"  [[12]] [1] "a-aaa" "a-aac" 

i'm not sure how begin tackle problem or shape/object class result should have. suggestions?

thanks reading

typing query google (i typed "modelling order book data in r") returns several links. 2nd points orderbook r package , this paper. hope helps , shows how did @ least. if not, please come question showing you've searched space.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -