| ml_backtest | R Documentation |
One-call backtest wrapper (tabular features)
ml_backtest(
features_list,
labels,
fit_fn,
predict_fn,
schedule = list(is = 156L, oos = 4L, step = 4L),
group = c("pooled", "per_symbol", "per_group"),
transform = c("none", "zscore", "rank"),
selection = list(top_k = 15L, max_per_group = NULL),
group_map = NULL,
weighting = list(method = "softmax", temperature = 12, floor = 0),
caps = list(max_per_symbol = 0.1, max_per_group = NULL),
turnover = NULL,
prices,
initial_capital = 1e+05,
name = "ML backtest"
)
features_list |
list of wide panels (each: |
labels |
Wide label panel (Date + symbols). |
fit_fn |
function |
predict_fn |
function |
schedule |
list with elements |
group |
one of |
transform |
|
selection |
list: |
group_map |
optional |
weighting |
list: |
caps |
list: |
turnover |
Optional turnover cap settings (currently advisory/unused). |
prices |
price panel used by the backtester ( |
initial_capital |
starting capital. |
name |
string for the backtest result. |
list: scores, mask, weights, backtest.
data(sample_prices_weekly); data(sample_prices_daily)
mom <- panel_lag(calc_momentum(sample_prices_weekly, 12), 1)
vol <- panel_lag(align_to_timeframe(
calc_rolling_volatility(sample_prices_daily, 20),
sample_prices_weekly$Date, "forward_fill"), 1)
Y <- make_labels(sample_prices_weekly, 4, "log")
fit_lm <- function(X,y){ Xc <- cbind(1,X); list(coef=stats::lm.fit(Xc,y)$coefficients) }
pred_lm <- function(m,X){ as.numeric(cbind(1,X) %*% m$coef) }
res <- ml_backtest(list(mom=mom, vol=vol), Y, fit_lm, pred_lm,
schedule = list(is=52,oos=4,step=4),
transform = "zscore",
selection = list(top_k=10),
weighting = list(method="softmax", temperature=12),
caps = list(max_per_symbol=0.10),
prices = sample_prices_weekly, initial_capital = 1e5)
res$backtest
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.