Skip to content

Commit eb15e6c

Browse files
committed
New nonexported function selectBacktests()
1 parent f953ec2 commit eb15e6c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

R/backtestSummary.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,17 @@ mergeBacktests <- function(bt1, bt2) {
301301
attr(bt_merged, "benchmark_index") <- attr(bt2, "benchmark_index") + length(bt1)
302302
return(bt_merged)
303303
}
304+
305+
306+
selectBacktests <- function(bt, portfolio_names = names(bt)) {
307+
bt_selected <- bt[c(portfolio_names)]
308+
num_portfolios <- length(bt_selected)
309+
if (attr(bt, "contain_benchmark"))
310+
bt_selected <- c(bt_selected, bt[attr(bt, "benchmark_index")])
311+
attr(bt_selected, "portfolio_index") <- c(1:num_portfolios)
312+
attr(bt_selected, "contain_benchmark") <- attr(bt, "contain_benchmark")
313+
attr(bt_selected, "benchmark_index") <- if (attr(bt, "contain_benchmark")) c(num_portfolios:(num_portfolios+length(attr(bt, "benchmark_index"))-1))
314+
else integer(0)
315+
return(bt_selected)
316+
}
317+

0 commit comments

Comments
 (0)