calc_var_ohlc_r | R Documentation |
Calculate the variance of an OHLC time series, using different range estimators for variance.
calc_var_ohlc_r(ohlc, method = "yang_zhang", scalit = TRUE)
ohlc |
An OHLC time series of prices in xts format. |
method |
A character string representing the method for estimating variance. The methods include:
(default is |
scalit |
Boolean argument: should the returns be divided by the
number of seconds in each period? (default is |
The function calc_var_ohlc_r()
calculates the variance
from all the different intra-day and day-over-day returns (defined as the
differences of OHLC prices), using several different variance
estimation methods.
The default method is "yang_zhang"
, which theoretically has the
lowest standard error among unbiased estimators.
The methods "close"
, "garman_klass_yz"
, and
"yang_zhang"
do account for close-to-open price jumps, while the
methods "garman_klass"
and "rogers_satchell"
do not account
for close-to-open price jumps.
If scalit
is TRUE
(the default), then the returns are divided
by the differences of the time index (which scales the variance to the
units of variance per second squared.) This is useful when calculating the
variance from minutely bar data, because dividing returns by the number of
seconds decreases the effect of overnight price jumps. If the time index is
in days, then the variance is equal to the variance per day squared.
The function calc_var_ohlc_r()
is implemented in R
code.
A single numeric value equal to the variance.
# Calculate the variance of SPY returns
HighFreq::calc_var_ohlc_r(HighFreq::SPY, method="yang_zhang")
# Calculate variance without accounting for overnight jumps
HighFreq::calc_var_ohlc_r(HighFreq::SPY, method="rogers_satchell")
# Calculate the variance without scaling the returns
HighFreq::calc_var_ohlc_r(HighFreq::SPY, scalit=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.