ohlc_variance | R Documentation |
Calculates the point variance estimates from individual rows of OHLC prices (rows of data), using the squared differences of OHLC prices at each point in time, without averaging them over time.
ohlc_variance(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 ohlc_variance()
calculates a time series of point
variance estimates of percentage returns, from OHLC prices, without
averaging them over time. For example, the method "close"
simply
calculates the squares of the differences of the log Close prices.
The other methods calculate the squares of other possible differences of the log OHLC prices. This way the point variance estimates only depend on the price differences within individual rows of data (and possibly from the neighboring rows.) All the methods are implemented assuming zero drift, since the calculations are performed only for a single row of data, at a single point in time.
The user can choose from several different variance estimation methods. 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. The default method is "yang_zhang"
, which
theoretically has the lowest standard error among unbiased estimators.
The point variance estimates can be passed into function roll_vwap()
to perform averaging, to calculate rolling variance estimates. This is
appropriate only for the methods "garman_klass"
and
"rogers_satchell"
, since they don't require subtracting the rolling
mean from the point variance estimates.
The point variance estimates can also be considered to be technical indicators, and can be used as inputs into trading models.
If scalit
is TRUE
(the default), then the variance is divided
by the squared differences of the time index (which scales the variance to
units of variance per second squared.) This is useful for example, when
calculating intra-day variance from minutely bar data, because dividing
returns by the number of seconds decreases the effect of overnight price
jumps.
If scalit
is TRUE
(the default), then the variance is
expressed in the scale of the time index of the OHLC time series.
For example, if the time index is in seconds, then the variance is given in
units of variance per second squared. If the time index is in days, then
the variance is equal to the variance per day squared.
The time index of the ohlc
time series is assumed to be in
POSIXct format, so that its internal value is equal to the number of
seconds that have elapsed since the epoch.
The function ohlc_variance()
performs similar calculations to the
function volatility()
from package
TTR, but it
assumes zero drift, and doesn't calculate a running sum using
runSum()
. It's also a little faster because it performs less data
validation.
An xts time series with a single column and the same number of
rows as the argument ohlc
.
# Create minutely OHLC time series of random prices
ohlc <- HighFreq::random_ohlc()
# Calculate variance estimates for ohlc
var_running <- HighFreq::ohlc_variance(ohlc)
# Calculate variance estimates for SPY
var_running <- HighFreq::ohlc_variance(HighFreq::SPY, method="yang_zhang")
# Calculate SPY variance without overnight jumps
var_running <- HighFreq::ohlc_variance(HighFreq::SPY, method="rogers_satchell")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.