calc_var_ag | R Documentation |
Calculate the variance of returns aggregated over the end points.
calc_var_ag(pricev, step = 1L)
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 |
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.
The variance of aggregated returns.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.