calc_var_ohlc_ag | R Documentation |
Calculate the variance of aggregated OHLC prices using different price range estimators.
calc_var_ohlc_ag(
ohlc,
step,
method = "yang_zhang",
closel = 0L,
scale = TRUE,
index = 0L
)
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:
(The default is the |
closel |
A vector with the lagged close prices
of the OHLC time series. This is an optional argument. (The
default is |
scale |
Boolean argument: Should the returns be divided
by the time index, the number of seconds in each period? (The default is
|
index |
A vector with the time index of the time
series. This is an optional argument (the default is |
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.
The variance of aggregated OHLC prices.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.