backtestChartSharpeRatio {portfolioBacktest}R Documentation

Chart of the rolling Sharpe ratio over time for a single backtest

Description

Create chart of the rolling Sharpe ratio over time for a single backtest obtained with the function portfolioBacktest. By default the chart is based on the package ggplot2, but the user can also specify a plot based on PerformanceAnalytics.

Usage

backtestChartSharpeRatio(
  bt,
  portfolios = names(bt),
  dataset_num = 1,
  lookback = 100,
  by = 1,
  gap = lookback,
  bars_per_year = 252,
  type = c("ggplot2", "simple"),
  ...
)

Arguments

bt

Backtest results as produced by the function portfolioBacktest.

portfolios

String with portfolio names to be charted. Default charts all portfolios in the backtest.

dataset_num

Dataset index to be charted. Default is dataset_num = 1.

lookback

Length of the lookback rolling window in periods (default is 100).

by

Intervals at which the Sharpe ratio is to be calculated (default is equal to 1).

gap

Initial number of periods to skip (default is equal to lookback).

bars_per_year

Number of bars/periods per year (default is 252).

type

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

...

Additional parameters.

Author(s)

Daniel P. Palomar and Rui Zhou

See Also

summaryBarPlot, backtestBoxPlot, backtestChartCumReturn, backtestChartStackedBar, backtestChartDrawdown

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 chart
backtestChartSharpeRatio(bt)



[Package portfolioBacktest version 0.4.1 Index]