R/pt.btavg.R

Defines functions pt.btavg

Documented in pt.btavg

###############################################################################################
##### batting average
###############################################################################################

#' @name pt.btavg
#' @aliases pt.btavg
#' @title Batting average
#' @description The batting average of the asset is the ratio between the number of periods
#' where the asset outperforms a benchmark and the total number of periods.
#' @usage pt.btavg(ar,br)
#' @param ar :a vector of a risk asset return
#' @param br :a vector of a benchmark return
#' @examples artn <- runif(100,-1,1)
#' brtn <- runif(100,-1,1)
#' pt.btavg(artn,brtn)

pt.btavg <- function(ar,br){

  n <- length(ar)

  dirt <- ar - br

  outperform <- length(dirt[dirt > 0])

  bta <- outperform/n

  return(bta)

}

Try the YRmisc package in your browser

Any scripts or data that you put into this service are public.

YRmisc documentation built on March 25, 2020, 5:13 p.m.