summaryBarPlot: Create barplot from backtest summary

View source: R/plotsNtables.R

summaryBarPlotR Documentation

Create barplot from backtest summary

Description

After performing a backtest with portfolioBacktest and obtaining a summary of the performance measures with backtestSummary, this function creates a barplot from the summary. By default the plot is based on the package ggplot2, but the user can also specify a simple base plot.

Usage

summaryBarPlot(bt_summary, measures = NULL, type = c("ggplot2", "simple"), ...)

Arguments

bt_summary

Backtest summary as obtained from the function backtestSummary.

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', etc.

type

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

...

Additional parameters (only used for plot type = "simple"); for example: mar for margins as in par(), inset for the legend inset as in legend(), legend_loc for the legend location as in legend().

Author(s)

Daniel P. Palomar and Rui Zhou

See Also

summaryTable, backtestBoxPlot, 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 obtain the table
bt_summary_median <- backtestSummary(bt)
summaryBarPlot(bt_summary_median, measures = c("max drawdown", "annual volatility"))
summaryBarPlot(bt_summary_median, measures = c("max drawdown", "annual volatility"), 
               type = "simple")



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