backtestTable: Table with portfolio backtest results

View source: R/backtestSummary.R

backtestTableR Documentation

Table with portfolio backtest results

Description

Create table with the results from a portfolio backtest.

Usage

backtestTable(
  bt,
  portfolio_indexes = NA,
  portfolio_names = NA,
  show_benchmark = TRUE,
  measures = NULL
)

Arguments

bt

Backtest results as produced by the function portfolioBacktest.

portfolio_indexes

Numerical vector of portfolio indexes whose performance will be summarized, e.g., c(1, 2) means to summarize the performance of the first and second portfolios recorded in bt.

portfolio_names

String vector of portfolio names whose performance will be summarized, e.g., c("EWP", "GMVP") means to summarize the performance of portfolios with names "EWP" and "GMVP" in bt (default is names(bt) except the benchmark names). Only considered when portfolio_indexes is not passed.

show_benchmark

Logical value indicating whether to include benchmarks in the summary (default is TRUE).

measures

String vector to select performane measures (default is all) from "Sharpe ratio", "max drawdown", "annual return", "annual volatility", "Sterling ratio", "Omega ratio", "ROT bps", "error", "cpu time", and "error_message".

Value

List with the following elements:

<performance criterion>

One item per performance measures as selected by argument measures.

error

Error status (TRUE or FALSE) for each portfolio over each dataset (TRUE is when the portfolio function generates an error or the maximum CPU time is exceeded).

cpu time

CPU usage by each portfolio function over each dataset.

error_message

Error messages generated by each portfolio function over each dataset. Useful for debugging purposes.

Author(s)

Rui Zhou and Daniel P. Palomar

Examples


library(portfolioBacktest)
data(dataset10)  # load dataset

# define your own portfolio function
EWP_portfolio <- function(dataset, ...) {
  N <- ncol(dataset$adjusted)
  return(rep(1/N, N))
}

# do backtest
bt <- portfolioBacktest(list("EWP" = EWP_portfolio), dataset10)

# show the backtest results in table
bt_tab <- backtestTable(bt)
bt_tab[c("Sharpe ratio", "max drawdown")]



dppalomar/portfolioBacktest documentation built on April 27, 2022, 3:27 a.m.