R/trade_size_stats.R

Defines functions trade.size.stats

Documented in trade.size.stats

#' generate descriptive statistics and quantiles for trades
#'
#' @param symbol string defining the symbol to analyze
#' @param on timespan to use for segmenting differences, using [xts::endpoints]
#'
#' @return
#'
#' @examples
#' @export
trade.size.stats <- function(symbol, on) {
  .ob    <- getOB()
  trades <- .ob[[symbol]]$trades
  if(is.null(trades)) stop('no trades found for ',symbol)
  ends   <- endpoints(trades, on)
  trade.mean <- period.apply(trades$Volume, INDEX=ends,FUN=mean)
  trade.sd <- period.apply(trades$Volume, INDEX=ends,FUN=sd)
  trade.quantiles <- period.apply(trades$Volume, INDEX=ends,FUN=quantile, probs=c(0.01, 0.25, 0.5, 0.75, 0.99), na.rm=TRUE)
  stats <- cbind(trade.mean, trade.sd, trade.quantiles)
  colnames(stats) <- c("Trade.Mean", "Trade.Sd", "Trade.P01", "Trade.P25", "Trade.P50", "Trade.P75", "Trade.P99")
  stats
}

###############################################################################
# obmodeling: Parsing, analysis, visualization of L1 and L2 order book data
# Copyright (c) 2017- Jeffrey Mazar and Brian G. Peterson
#
# This library is distributed under the terms of the GNU Public License (GPL)
# for full details see https://www.gnu.org/licenses/licenses.en.html
#
###############################################################################
jmazar/obmodeling documentation built on March 27, 2022, 12:55 a.m.