| roll_ohlc | R Documentation |
Given a time series of prices at a higher periodicity (say seconds), it calculates the OHLC prices at a lower periodicity (say minutes).
roll_ohlc(timeser, endd)
timeser |
A time series or a matrix with multiple columns of data. |
\emph{endd} |
An integer vector of end points. |
The function roll_ohlc() performs a loop over the end points
endd, along the rows of the data timeser. At each end point,
it selects the past rows of the data timeser, starting at the first
bar after the previous end point, and then calls the function
agg_ohlc() on the selected data timeser to calculate the
aggregations.
The function roll_ohlc() can accept either a single column of data
or four columns of OHLC data.
It can also accept an additional column containing the trading volume.
The function roll_ohlc() performs a similar aggregation as the
function to.period() from package
xts.
A matrix with OHLC data, with the number of rows equal to the number of endd minus one.
## Not run:
# Define matrix of OHLC data
ohlc <- rutils::etfenv$VTI[, 1:5]
# Define end points at 25 day intervals
endd <- HighFreq::calc_endpoints(NROW(ohlc), step=25)
# Aggregate over endd:
ohlcagg <- HighFreq::roll_ohlc(timeser=ohlc, endd=endd)
# Compare with xts::to.period()
ohlcagg_xts <- .Call("toPeriod", ohlc, as.integer(endd+1), TRUE, NCOL(ohlc), FALSE, FALSE, colnames(ohlc), PACKAGE="xts")
all.equal(ohlcagg, coredata(ohlcagg_xts), check.attributes=FALSE)
## End(Not run) # end dontrun
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.