Function deletes entries with prices that are above the ask plus the bid-ask spread. Similar for entries with prices below the bid minus the bid-ask spread.
rmTradeOutliersUsingQuotes(tData, qData, lagQuotes = 2)
a data.table or xts object containing the time series data, with at least the column "PRICE", containing the transaction price.
a data.table or xts object containing the time series data with at least the columns "BID" and "OFR", containing the bid and ask prices.
a numeric of length 1 that denotes how many seconds to lag the quotes. Default is 2 seconds. See Details.
xts or data.table object depending on input
Note: in order to work correctly, the input data of this function should be cleaned trade (tData) and quote (qData) data respectively. In older high frequency datasets the trades frequently lag the quotes. In newer datasets this tends to happen only during extreme market activity when exchange networks are at maximum capacity.
Vergote, O. (2005). How to match trades and quotes for NYSE stocks? K.U.Leuven working paper.