# \donttest{
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
# }
Run the code above in your browser using DataLab