# \donttest{
if (requireNamespace("PortfolioTesteR", quietly = TRUE)) {
library(PortfolioTesteR)
data(sample_prices_weekly, package = "PortfolioTesteR")
# Simple feature
mom12 <- PortfolioTesteR::calc_momentum(sample_prices_weekly, 12)
feats <- list(mom12 = mom12)
fit_first <- function(X, y, ...) list()
predict_first <- function(model, Xnew, ...) as.numeric(Xnew[[1]])
sch <- list(is = 52L, oos = 26L, step = 26L)
syms <- setdiff(names(sample_prices_weekly), "Date")
gmap <- data.frame(Symbol = syms,
Group = rep(c("G1","G2"), length.out = length(syms)))
bt_pooled <- ml_backtest_multi(feats, sample_prices_weekly, c(4L),
fit_first, predict_first, sch,
selection = list(top_k = 5L),
weighting = list(method = "softmax", temperature = 12),
caps = list(max_per_symbol = 0.10),
group_mode = "pooled")
bt_neutral <- ml_backtest_multi(feats, sample_prices_weekly, c(4L),
fit_first, predict_first, sch,
selection = list(top_k = 5L),
weighting = list(method = "softmax", temperature = 12),
caps = list(max_per_symbol = 0.10),
group_mode = "per_group",
group_map = gmap)
out <- pt_collect_results(
bt_pooled_list = bt_pooled,
bt_neutral_list = bt_neutral,
prices = sample_prices_weekly,
horizons = c(4L),
split_date = as.Date("2019-01-01"),
cost_bps = c(5, 15),
freq = 52,
ic_roll_window = 13L
)
names(out)
str(out[["H4w"]]$perf_tables)
}# }
Run the code above in your browser using DataLab