add_performance {portfolioBacktest} | R Documentation |
Add a new performance measure to backtests
Description
Add a new performance measure to backtests
Usage
add_performance(bt, name, fun, desired_direction = 1)
Arguments
bt |
Backtest results as produced by the function |
name |
String with name of new performance measure. |
fun |
Function to compute new performance measure from any element returned by
|
desired_direction |
Number indicating whether the new measure is desired to be larger (1), which is the default, or smaller (-1). |
Value
List with the portfolio backtest results, see portfolioBacktest
.
Author(s)
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)
# add a new performance measure
bt <- add_performance(bt, name = "SR arithmetic",
fun = function(return, ...)
PerformanceAnalytics::SharpeRatio.annualized(return,
geometric = FALSE))
bt <- add_performance(bt, name = "avg leverage", desired_direction = -1,
fun = function(w_bop, ...)
if(anyNA(w_bop)) NA else mean(rowSums(abs(w_bop))))
[Package portfolioBacktest version 0.4.1 Index]