roll_stats | R Documentation |
Calculate a vector of statistics over an OHLC time series, and calculate a rolling mean over the statistics.
roll_stats(
ohlc,
calc_stats = "ohlc_variance",
look_back = 11,
weighted = TRUE,
...
)
... |
additional parameters to the function |
ohlc |
An OHLC time series of prices and trading volumes, in xts format. |
calc_stats |
The name of the function for estimating statistics of a single row of OHLC data, such as volatility, skew, and higher moments. |
look_back |
The size of the look-back interval, equal to the number of rows of data used for calculating the rolling mean. |
weighted |
Boolean argument: should statistic be weighted by
trade volume? (default |
The function roll_stats()
calculates a vector of statistics
over an OHLC time series, such as volatility, skew, and higher
moments. The statistics could also be any other aggregation of a single
row of OHLC data, for example the High price minus the
Low price squared. The length of the vector of statistics is equal
to the number of rows of the argument ohlc
. Then it calculates a
trade volume weighted rolling mean over the vector of statistics over and
calculate statistics.
An xts time series with a single column and the same number of
rows as the argument ohlc
.
# Calculate time series of rolling variance and skew estimates
var_rolling <- roll_stats(ohlc=HighFreq::SPY, look_back=21)
skew_rolling <- roll_stats(ohlc=HighFreq::SPY, calc_stats="ohlc_skew", look_back=21)
skew_rolling <- skew_rolling/(var_rolling)^(1.5)
skew_rolling[1, ] <- 0
skew_rolling <- rutils::na_locf(skew_rolling)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.