jonathancornelissen / highfrequency

The highfrequency package contains an extensive toolkit for the use of highfrequency financial data in R. It contains functionality to manage, clean and match highfrequency trades and quotes data. Furthermore, it enables users to: calculate easily various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity.
147 stars 63 forks source link

Error when DIRECTION is all 1s. #99

Open imitationsasquatch opened 1 year ago

imitationsasquatch commented 1 year ago

highfrequency::getLiquidityMeasures will report the following error when DIRECTION is all 1s: Error in highfrequency::getLiquidityMeasures(matched, win = 300) : DIRECTION provided, but is not -1 and 1 In addition: Warning message: In if (sort(unique(tqData$DIRECTION)) != c(-1, 1)) { : the condition has length > 1 and only the first element will be used

Can be reproduced with the following: df <- data.table(DT = c(as_datetime("2018-09-01 12:00:00"), as_datetime("2018-09-01 12:00:01"), as_datetime("2018-09-01 12:00:06")), SYMBOL = c("AAA", "AAA", "AAA"), BID = c( 2, 3, 3), OFR = c(1, 2, 3), OFRSIZ = c( 10, 10 ,10), BIDSIZ = c(10, 10 ,10), QUOTEXX = c("A"), MIDQUOTE = c(1.5, 2.5, 3), EX = c("A"), PRICE = c(2, 2, 2), SIZE = c(10, 10 ,10), DIRECTION = c(1, 1, 1) ) liq <- getLiquidityMeasures(df, win = 300)

onnokleen commented 1 year ago

Thanks for reporting the bug. It will be fixed in the next release!

onnokleen commented 11 months ago

@kboudt Can you close this issue as the new version is on CRAN?