agg_stats_r: Calculate the aggregation (weighted average) of a statistical...

View source: R/HighFreq.R

agg_stats_rR Documentation

Calculate the aggregation (weighted average) of a statistical estimator over a OHLC time series using R code.

Description

Calculate the aggregation (weighted average) of a statistical estimator over a OHLC time series using R code.

Usage

agg_stats_r(ohlc, calc_bars = "ohlc_variance", weighted = TRUE, ...)

Arguments

...

additional parameters to the function calc_bars.

ohlc

An OHLC time series of prices and trading volumes, in xts format.

calc_bars

A character string representing a function for calculating statistics for individual OHLC bars.

weighted

Boolean argument: should estimate be weighted by the trading volume? (default is TRUE)

Details

The function agg_stats_r() calculates a single number representing the volume weighted average of statistics of individual OHLC bars. It first calls the function calc_bars to calculate a vector of statistics for the OHLC bars. For example, the statistic may simply be the difference between the High minus Low prices. In this case the function calc_bars would calculate a vector of High minus Low prices. The function agg_stats_r() then calculates a trade volume weighted average of the vector of statistics.

The function agg_stats_r() is implemented in R code.

Value

A single numeric value equal to the volume weighted average of an estimator over the time series.

Examples

# Calculate weighted average variance for SPY (single number)
variance <- agg_stats_r(ohlc=HighFreq::SPY, calc_bars="ohlc_variance")
# Calculate time series of daily skew estimates for SPY
skew_daily <- apply.daily(x=HighFreq::SPY, FUN=agg_stats_r, calc_bars="ohlc_skew")


algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.