backtestBoxPlot: Create boxplot from backtest results

View source: R/plotsNtables.R

backtestBoxPlotR Documentation

Create boxplot from backtest results

Description

Create boxplot from a portfolio backtest obtained with the function portfolioBacktest. By default the boxplot is based on the package ggplot2 (also plots a dot for each single backtest), but the user can also specify a simple base plot.

Usage

backtestBoxPlot(
  bt,
  measure = "Sharpe ratio",
  ref_portfolio = NULL,
  type = c("ggplot2", "simple"),
  ...
)

Arguments

bt

Backtest results as produced by the function portfolioBacktest.

measure

String to select a performane measure from "Sharpe ratio", "max drawdown", "annual return", "annual volatility", "Sterling ratio", "Omega ratio", and "ROT bps". Default is "Sharpe ratio".

ref_portfolio

Reference portfolio (whose measure will be subtracted). Default is NULL.

type

Type of plot. Valid options: "ggplot2", "simple". Default is "ggplot2".

...

Additional parameters. For example: mar for margins as in par() (for the case of plot type = "simple"); and alpha for the alpha of each backtest dot (for the case of plot type = "ggplot2"), set to 0 to remove the dots.

Author(s)

Daniel P. Palomar and Rui Zhou

See Also

summaryBarPlot, backtestChartCumReturn, backtestChartDrawdown, backtestChartStackedBar

Examples


library(portfolioBacktest)
data(dataset10)  # load dataset

# define your own portfolio function
quintile_portfolio <- function(data, ...) {
  X <- diff(log(data$adjusted))[-1]  
  N <- ncol(X)
  ranking <- sort(colMeans(X), decreasing = TRUE, index.return = TRUE)$ix
  w <- rep(0, N)
  w[ranking[1:round(N/5)]] <- 1/round(N/5)
  return(w)
}

# do backtest
bt <- portfolioBacktest(list("Quintile" = quintile_portfolio), dataset10,
                        benchmark = c("1/N", "index"))

# now we can plot
backtestBoxPlot(bt, "Sharpe ratio")
backtestBoxPlot(bt, "Sharpe ratio", type = "simple")



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