# reduce number of threads to pass CRAN checks (you can ignore this)
data.table::setDTthreads(1)
# simulate open, high, low, and close prices with spread 1%
x <- sim(n = 1000, spread = 0.01)
# estimate the spread using a rolling window
s <- edge_rolling(x$Open, x$High, x$Low, x$Close, width = 21)
tail(s)
# estimate the spread using custom endpoints
ep <- c(3, 35, 100)
s <- edge_rolling(x$Open, x$High, x$Low, x$Close, width = ep)
s[c(35, 100)]
# equivalent to
edge(x$Open[3:35], x$High[3:35], x$Low[3:35], x$Close[3:35])
edge(x$Open[35:100], x$High[35:100], x$Low[35:100], x$Close[35:100])
# estimate the spread using an expanding window
s <- edge_rolling(x$Open, x$High, x$Low, x$Close, width = 1:nrow(x))
tail(s)
# equivalent to
s <- edge_expanding(x$Open, x$High, x$Low, x$Close, na.rm = FALSE)
tail(s)
Run the code above in your browser using DataLab