calc_var_ohlc_ag: Calculate the variance of aggregated _OHLC_ prices using...

View source: R/RcppExports.R

calc_var_ohlc_agR Documentation

Calculate the variance of aggregated OHLC prices using different price range estimators.

Description

Calculate the variance of aggregated OHLC prices using different price range estimators.

Usage

calc_var_ohlc_ag(
  ohlc,
  step,
  method = "yang_zhang",
  closel = 0L,
  scale = TRUE,
  index = 0L
)

Arguments

ohlc

A time series or a matrix of OHLC prices.

step

The number of time periods in each interval between neighboring end points.

method

A character string representing the price range estimator for calculating the variance. The estimators include:

  • "close" close-to-close estimator,

  • "rogers_satchell" Rogers-Satchell estimator,

  • "garman_klass" Garman-Klass estimator,

  • "garman_klass_yz" Garman-Klass with account for close-to-open price jumps,

  • "yang_zhang" Yang-Zhang estimator,

(The default is the method = "yang_zhang".)

closel

A vector with the lagged close prices of the OHLC time series. This is an optional argument. (The default is closel = 0).

scale

Boolean argument: Should the returns be divided by the time index, the number of seconds in each period? (The default is scale = TRUE).

index

A vector with the time index of the time series. This is an optional argument (the default is index = 0).

Details

The function calc_var_ohlc_ag() calculates the variance of OHLC prices aggregated over the end points.

It first calculates the end points spaced apart by the number of periods equal to the argument step. Then it aggregates the OHLC prices to the end points. Finally it calculates the variance of the aggregated OHLC prices.

The choice of the first end point is arbitrary, so calc_var_ohlc_ag() calculates the different end points for all the possible starting points. It then calculates the variance values for all the different end points and averages them.

The aggregated volatility \sigma_t increases with the length of the aggregation interval \Delta t. The aggregated volatility increases as the length of the aggregation interval \Delta t raised to the power of the Hurst exponent H:

\sigma_t = \sigma {\Delta t}^H

Where \sigma is the daily return volatility.

The function calc_var_ohlc_ag() can therefore be used to calculate the Hurst exponent from the variance ratio.

Value

The variance of aggregated OHLC prices.

Examples

## Not run: 
# Calculate the log ohlc prices
ohlc <- log(rutils::etfenv$VTI)
# Calculate the daily variance of percentage returns
calc_var_ohlc_ag(ohlc, step=1)
# Calculate the variance of returns aggregated over 21 days
calc_var_ohlc_ag(ohlc, step=21)
# The variance over 21 days is approximately 21 times the daily variance
21*calc_var_ohlc_ag(ohlc, step=1)

## End(Not run)


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