calc_var_ag: Calculate the variance of returns aggregated over the end...

View source: R/RcppExports.R

calc_var_agR Documentation

Calculate the variance of returns aggregated over the end points.

Description

Calculate the variance of returns aggregated over the end points.

Usage

calc_var_ag(pricev, step = 1L)

Arguments

pricev

A time series or a matrix of prices.

step

The number of time periods in each interval between neighboring end points (the default is step = 1).

Details

The function calc_var_ag() calculates the variance of returns 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 calculates the aggregated returns by differencing the prices pricev calculated at the end points. Finally it calculates the variance of the returns.

The choice of the first end point is arbitrary, so calc_var_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_ag() can therefore be used to calculate the Hurst exponent from the variance ratio.

Value

The variance of aggregated returns.

Examples

## Not run: 
# Calculate the prices
closep <- na.omit(rutils::etfenv$prices[, c("XLP", "VTI")])
closep <- log(closep)
# Calculate the variance of daily returns
calc_var_ag(prices, step=1)
# Calculate the variance using R
sapply(rutils::diffit(closep), var)
# Calculate the variance of returns aggregated over 21 days
calc_var_ag(prices, step=21)
# The variance over 21 days is approximately 21 times the daily variance
21*calc_var_ag(prices, step=1)

## End(Not run)


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