roll_ohlc: Aggregate a time series to an _OHLC_ time series with lower...

View source: R/RcppExports.R

roll_ohlcR Documentation

Aggregate a time series to an OHLC time series with lower periodicity.

Description

Given a time series of prices at a higher periodicity (say seconds), it calculates the OHLC prices at a lower periodicity (say minutes).

Usage

roll_ohlc(tseries, endd)

Arguments

tseries

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

endd

An integer vector of end points.

Details

The function roll_ohlc() performs a loop over the end points endd, along the rows of the data tseries. At each end point, it selects the past rows of the data tseries, starting at the first bar after the previous end point, and then calls the function agg_ohlc() on the selected data tseries 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.

Value

A matrix with OHLC data, with the number of rows equal to the number of endd minus one.

Examples

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


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