#' Extract Performance Stats from a Backtest Parameter Screen
#'
#' @param screen_results list containing backtest parameter screen results
#' @param stat_parameter character indicating which parameter to extract. One of Annualized Return, Calmar Ratio, Treynor Ratio, Burke Ratio, CAPM beta, CDaR, Max. Drawdown, Annualized Turnover
#' @param spread logical, if results including spread
#' @param par1_seqf parameter 1 sequence
#' @param par2_seqf parameter 2 sequence
#'
#' @importFrom magrittr %>% %<>%
#'
#' @return
#' @export
#'
#' @examples pull_perf_stats(strategy_screen_results, "Annualized Return")
pull_perf_stats <- function(screen_results,
stat_parameter = "Annualized Return",
spread = FALSE,
par1_seqf = par1_seq,
par2_seqf = par2_seq) {
cols <- screen_results[[1]][[1]] %>% names() %>%
.[grepl("stats", .)]
if (spread) {
cols %<>% .[grepl("spread", .)]
} else {
cols %<>% .[!grepl("spread", .)]
}
rows <- screen_results[[1]][[1]][[cols]] %>% rownames()
stat_value <- match.arg(stat_parameter, rows, several.ok = FALSE)
sapply(unlist(screen_results, recursive = FALSE), `[[`, cols) %>%
do.call(cbind, .) %>%
.[rows %in% stat_value, ] %>%
matrix(., nrow = length(par1_seqf), byrow = TRUE) %>%
`colnames<-`(par2_seqf) %>%
`rownames<-`(par1_seqf) %>%
t() %>% as.data.frame()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.