Match the trades and quotes of the input data. All trades are retained and the latest bids and offers are retained, while 'old' quotes are discarded.
matchTradesQuotes(
tData,
qData,
lagQuotes = 0,
BFM = FALSE,
backwardsWindow = 3600,
forwardsWindow = 0.5,
plot = FALSE,
...
)
Depending on the input data type, we return either a data.table
or an xts
object containing the matched trade and quote data.
When using the BFM algorithm, a report of the matched and unmatched trades are also returned (This is omitted when we call this function from the tradesCleanupUsingQuotes
function).
data.table
or xts-object containing the trade data possibly with multiple symbols and over multiple days possible
data.table
or xts-object containing the quote data possibly with multiple symbols and over multiple days possible
numeric, number of seconds the quotes are registered faster than the trades (should be round and positive). Default is 0. For older datasets, i.e. before 2010, it may be a good idea to set this to e.g. 2. See Vergote (2005)
a logical determining whether to conduct 'Backwards - Forwards matching' of trades and quotes. The algorithm tries to match trades that fall outside the bid - ask and first tries to match a small window forwards and if this fails, it tries to match backwards in a bigger window. The small window is a tolerance for inaccuracies in the timestamps of bids and asks. The backwards window allow for matching of late reported trades. I.e. block trades.
a numeric denoting the length of the backwards window used when BFM = TRUE
. Default is 3600, corresponding to one hour.
a numeric denoting the length of the forwards window used when BFM = TRUE
. Default is 0.5, corresponding to one half second.
a logical denoting whether to visualize the forwards, backwards, and unmatched trades in a plot.
used internally. Don't set this parameter
Jonathan Cornelissen, Kris Boudt, Onno Kleen, and Emil Sjoerup.
Vergote, O. (2005). How to match trades and quotes for NYSE stocks? K.U.Leuven working paper.
Christensen, K., Oomen, R. C. A., Podolskij, M. (2014): Fact or Friction: Jumps at ultra high frequency. Journal of Financial Economics, 144, 576-599
# Multi-day input allowed
tqData <- matchTradesQuotes(sampleTData, sampleQData)
# Show output
tqData
Run the code above in your browser using DataLab