R/fun_PlotsAndAlphaTable.R

#' fun_PlotsAndAlphaTable
#'
#' @param period Period of which one want to have lagged values of
#' @param tablePeriods Period one want to have lagged values of in xtable. The range is the range of the plot
#' @param savePlot If oen want to save the plot
#'
#' @return List\
#'  \item{name ModelList}{Model, table and plot}
#'  \item{name xtable}{xtable which can be used directly in Latex of alpha statistics}
#' @export
#'
fun_PlotsAndAlphaTable <- function(period = c("days", "weeks", "months"),
                                   tablePeriods = c(1, 3, 6, 9, 12, 15, 18, 24),
                                   savePlot = TRUE) {
  outList <- list(
    Cum = fun_getLmStats(df = Cum.daily, period = period,
                             tablePeriods = tablePeriods, sign = FALSE,
                             name = "Cum", savePlot = savePlot),
    Cum.sign = fun_getLmStats(df = Cum.daily, period = period,
                                  tablePeriods = tablePeriods, sign = TRUE,
                                  name = "Cum", savePlot = savePlot),
    BTC = fun_getLmStats(df = BTC.daily, period = period,
                             tablePeriods = tablePeriods, sign = FALSE,
                             name = "BTC", savePlot = savePlot),
    BTC.sign = fun_getLmStats(df = BTC.daily, period = period,
                                  tablePeriods = tablePeriods, sign = TRUE,
                                  name = "BTC", savePlot = savePlot),
    ETH = fun_getLmStats(df = ETH.daily, period = period,
                             tablePeriods = tablePeriods, sign = FALSE,
                             name = "ETH", savePlot = savePlot),
    ETH.sign = fun_getLmStats(df = ETH.daily, period = period,
                                  tablePeriods = tablePeriods, sign = TRUE,
                                  name = "ETH", savePlot = savePlot),
    XRP = fun_getLmStats(df = XRP.daily, period = period,
                             tablePeriods = tablePeriods, sign = FALSE,
                             name = "XRP", savePlot = savePlot),
    XRP.sign = fun_getLmStats(df = XRP.daily, period = period,
                                  tablePeriods = tablePeriods, sign = TRUE,
                                  name = "XRP", savePlot = savePlot),
    BCH = fun_getLmStats(df = BCH.daily, period = period,
                             tablePeriods = tablePeriods, sign = FALSE,
                             name = "BCH", savePlot = savePlot),
    BCH.sign = fun_getLmStats(df = BCH.daily, period = period,
                                  tablePeriods = tablePeriods, sign = TRUE,
                                  name = "BCH", savePlot = savePlot)
  )
  tdayStats <- do.call(cbind, lapply(outList, function(x) {
    out <- x$table %>%
      dplyr::filter(Parameter == "alpha") %>%
      dplyr::select(`t value`)
    rownames(out) <- x$table[seq(1,nrow(x$table),2),1]
    return(out)
  }))
  colnames(tdayStats) <- names(outList)
  outXtable <- xtable::xtable(t(tdayStats))
  return(list(ModelList = outList,
              xtable = outXtable))
}
3schwartz/SpecialeScrAndFun documentation built on May 4, 2019, 6:29 a.m.