R/select.OHLC.R

#converts OHLC.. data into the format needed for function f
#' Title
#'
#' @param data OHLC data
#' @param fun function which uses time series data
#'
#' @return select.OHLC
#' @import quantmod
#' @export select.OHLC
#'
#'
#' @examples select.OHLC(msci_world, TTR:CCI)
select.OHLC <- function (data, fun) {

  #if fun is not a function create an OHLC object
  if (is.function(fun) == FALSE) {
    input_obj <- NA
    data_correct <- OHLC(data)
  } else {
    #get formal argument of function for condition
    input_obj <- names(formals(fun))[1]
  }

  #reformat OHLC object as needed for the function fun
  if (grepl("HLC", input_obj) == TRUE) {
    data_correct <- HLC(data)
  }
  if (grepl("x", input_obj) == TRUE) {
    data_correct <- Cl(data)
  }

  return(data_correct)
}
rengelke/quantTraiding_trato documentation built on Oct. 13, 2020, 12:01 p.m.