agg_ohlc: Aggregate a time series of data into a single bar of _OHLC_...

View source: R/RcppExports.R

agg_ohlcR Documentation

Aggregate a time series of data into a single bar of OHLC data.

Description

Aggregate a time series of data into a single bar of OHLC data.

Usage

agg_ohlc(timeser)

Arguments

timeser

A time series or a matrix with multiple columns of data.

Details

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 timeser. The high value as the maximum of the high column of timeser. The low value as the minimum of the low column of timeser. The close value as the close of the last row of timeser. The volume value as the sum of the volume column of timeser.

For a single column of data, the open, high, low, and close values are all the same.

Value

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 timeser).

Examples

## 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)  # end dontrun


algoquant/HighFreq documentation built on June 10, 2025, 3:54 p.m.