Recreating the LOB

September 10, 2017

(This article was first published on R and Finance, and kindly contributed to R-bloggers)

Update to GetHFData (Version 1.4) –

GetHFData newest version (1.4) allows the recreation of the LOB (limit order book) based on order data. A limit order book is the standard format that trading occurs in most exchanges. Order are sent and executed whenever there is a match of order prices from sellers and buyers. Recreating the LOB is a recursive problem where all trading orders must be sorted, added and organized into a LOB object. Based on the LOB, we have information about the mid quote, best bid/ask, spread and LOB depth. These variables are usually used in studies regarding market liquidity.

I want to thank Prof. Satchit Sagade and House of Finance – Goethe Uni for inviting me as a visiting researcher in June 2017. Not only I had a wonderful time there, most of the code for the LOB reconstruction was developed during my stay.

Be aware that recreating the LOB is a computer intensive problem. The current code is not optimized for speed and may take a long time to finish, even for a few periods of trading days. Here’s an example of usage for the new code:


first.time <- '10:00:00'
last.time <- '17:00:00' <- '2015-08-18' <- '2015-08-18'

type.output <- 'raw' 

my.assets <- 'PETR4F' 
type.matching <- 'exact' = 'equity-odds' <- 'orders' 

df.out <- ghfd_get_HF_data(my.assets =my.assets, 
                           type.matching = type.matching,
                           first.time = first.time,
                           last.time = last.time,
                           type.output = type.output)
df.lob <- ghfd_build_lob(df.out)

To leave a comment for the author, please follow the link and comment on their blog: R and Finance. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)