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

Volume bars using businessTimeAggregation function #75

Closed MislavSag closed 2 years ago

MislavSag commented 3 years ago

Hi ,

I am reading the new vignette. great work.

There is a section in te vignette which says:

On the other hand, ‘calendar time’ is not the only criterion on which to aggregate data, there are also so called business time measures. We include the businessTimeAggregation function which can do aggregation based on volume, volatility, and the intensity measure presented in Oomen (2006). The function samples a specified number of observations that are equally spaced based on the chosen measure.

I have tried to use above businessTimeAggregation function with volume as measure. I would expect this would create "volume bars", that is bars with approximately uniform distribution wrt volume. But sizes are very different across bars. I am not sure I understand what this function really do. I have read about tick, volume and dollar bars on one side, and imbalanced bars on other side, in De Prado book on Advanced ML in finance. Is it possible to construct this kind of bars with highfrequency package?

emilsjoerup commented 3 years ago

Hi,

I just looked at the code on my phone and I see how it can be confusing. Currently, the volume output is the last in the window of the given sample, which is..... suboptimal.

I will try to fix it tomorrow and get an update on the repo.

MislavSag commented 3 years ago

I have found the code for tick, volume and other bars in this package: https://github.com/nmatare/quanttools/. Maybe it can help somehow. It uses the same Rcpp function in constructing all bars.

MislavSag commented 3 years ago

I forgot to provide sample code:

library(QuantTools)
library(highfrequency)

# import data and cleaning
tick_data <- get_finam_data("AAPL", as.Date("2021-09-07"), as.Date("2021-09-07"), "tick")
setnames(tick_data, c("DT", "PRICE", "SIZE"))
tick_data$SYMBOL <- "AAPL"
tick_data_cleaned <- tradesCleanup(tDataRaw = tick_data)
print(tick_data_cleaned$report)
tick_data_cleaned <- tick_data_cleaned$tData

# aggreagtion
vol_bars <- businessTimeAggregation(tick_data_cleaned, measure = "volume")
print(vol_bars$pData)
# SIZE IS NOT UNIFORM