| ml_backtest_multi | R Documentation |
Convenience wrapper around ml_backtest() that repeats the
same specification across multiple horizons, returning a named list of
backtest objects keyed as "H1w", "H4w", "H13w", etc.
ml_backtest_multi(
features_list,
prices_weekly,
horizons,
fit_fn,
predict_fn,
schedule,
transform = "zscore",
selection = list(top_k = 20L),
weighting = list(method = "softmax", temperature = 12),
caps = list(max_per_symbol = 0.1),
group_mode = c("pooled", "per_group"),
group_map = NULL,
initial_capital = 1e+05,
name_prefix = "",
seed = NULL,
...
)
features_list |
Named list of data.tables with factor scores (each with a
|
prices_weekly |
Wide price table (weekly) with |
horizons |
Integer vector of horizons in weeks (e.g., |
fit_fn, predict_fn |
Model fit/predict closures as returned by
|
schedule |
Walk-forward schedule list with elements |
transform |
Feature transform (default |
selection |
List describing selection rules (e.g., |
weighting |
List describing weighting rules (e.g., |
caps |
List with exposure caps (e.g., |
group_mode |
|
group_map |
A two-column table with columns |
initial_capital |
Numeric. Starting capital for the backtest (default |
name_prefix |
Optional string prefixed to each backtest title. |
seed |
Optional integer. If provided, the same seed is set before each horizon’s backtest call to ensure deterministic tie-breaks. |
... |
Additional arguments forwarded to |
This function does not change core behavior; it only removes boilerplate when running identical specs across horizons and (optionally) grouping regimes. It preserves all defaults you pass for selection, weighting, transforms, caps, and schedule.
A named list of backtest objects (as returned by
ml_backtest()), with names like "H1w", "H4w", … .
library(PortfolioTesteR)
data(sample_prices_weekly, package = "PortfolioTesteR")
# Minimal features for the example
X <- ml_prepare_features(
prices_weekly = sample_prices_weekly,
include = c("mom12","mom26")
)
# Simple deterministic model
model <- ml_make_model("linear")
sched <- list(is = 156L, oos = 4L, step = 4L)
set.seed(42)
bt_list <- ml_backtest_multi(
features_list = X,
prices_weekly = sample_prices_weekly,
horizons = c(1L, 4L),
fit_fn = model$fit,
predict_fn = model$predict,
schedule = sched,
selection = list(top_k = 5L),
weighting = list(method = "softmax", temperature = 12),
caps = list(max_per_symbol = 0.10),
group_mode = "pooled",
name_prefix = "Demo ",
seed = 42
)
names(bt_list) # "H1w" "H4w"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.