ohlc_returns: Calculate single period percentage returns from either _TAQ_...

View source: R/HighFreq.R

ohlc_returnsR Documentation

Calculate single period percentage returns from either TAQ or OHLC prices.

Description

Calculate single period percentage returns from either TAQ or OHLC prices.

Usage

ohlc_returns(xtsv, lagg = 1, colnum = 4, scalit = TRUE)

Arguments

xtsv

An xts time series of either TAQ or OHLC data.

lagg

An integer equal to the number of time periods of lag. (default is 1)

colnum

The column number to extract from the OHLC data. (default is 4, or the Close prices column)

scalit

Boolean argument: should the returns be divided by the number of seconds in each period? (default is TRUE)

Details

The function ohlc_returns() calculates the percentage returns for either TAQ or OHLC data, defined as the difference of log prices. Multi-period returns can be calculated by setting the lag parameter to values greater than 1 (the default).

If scalit is TRUE (the default), then the returns are divided by the differences of the time index (which scales the returns to units of returns per second.)

The time index of the xtsv time series is assumed to be in POSIXct format, so that its internal value is equal to the number of seconds that have elapsed since the epoch.

If scalit is TRUE (the default), then the returns are expressed in the scale of the time index of the xtsv time series. For example, if the time index is in seconds, then the returns are given in units of returns per second. If the time index is in days, then the returns are equal to the returns per day.

The function ohlc_returns() identifies the xtsv time series as TAQ data when it has six columns, otherwise assumes it's OHLC data. By default, for OHLC data, it differences the Close prices, but can also difference other prices depending on the value of colnum.

Value

A single-column xts time series of returns.

Examples

# Calculate secondly returns from TAQ data
returns <- HighFreq::ohlc_returns(xtsv=HighFreq::SPY_TAQ)
# Calculate close to close returns
returns <- HighFreq::ohlc_returns(xtsv=HighFreq::SPY)
# Calculate open to open returns
returns <- HighFreq::ohlc_returns(xtsv=HighFreq::SPY, colnum=1)


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