agg_ohlc | R Documentation |
Aggregate a time series of data into a single bar of OHLC data.
agg_ohlc(tseries)
tseries |
A time series or a matrix with multiple columns of data. |
The function agg_ohlc()
aggregates a time series of data into a
single bar of OHLC data. It 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 agg_ohlc()
calculates the open value as equal to
the open value of the first row of tseries
.
The high value as the maximum of the high column of
tseries
.
The low value as the minimum of the low column of
tseries
.
The close value as the close of the last row of
tseries
.
The volume value as the sum of the volume column of
tseries
.
For a single column of data, the open, high, low, and close values are all the same.
A matrix containing a single row, with the open,
high, low, and close values, and also the total
volume (if provided as either the second or fifth column of
tseries
).
## Not run:
# Define matrix of OHLC data
ohlc <- coredata(rutils::etfenv$VTI[, 1:5])
# Aggregate to single row matrix
ohlcagg <- HighFreq::agg_ohlc(ohlc)
# Compare with calculation in R
all.equal(drop(ohlcagg),
c(ohlc[1, 1], max(ohlc[, 2]), min(ohlc[, 3]), ohlc[NROW(ohlc), 4], sum(ohlc[, 5])),
check.attributes=FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.