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(tseries)

Arguments

tseries

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

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

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)


algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.