# \donttest{
data(sample_prices_weekly)
mom12 <- PortfolioTesteR::calc_momentum(sample_prices_weekly, 12) # WIDE numeric
sel10 <- PortfolioTesteR::filter_top_n(mom12, 10) # WIDE logical/numeric
# Ensure logical mask
syms <- setdiff(names(sel10), "Date")
sel_mask <- data.table::as.data.table(sel10)
sel_mask[, (syms) := lapply(.SD, function(z) as.logical(as.integer(z))), .SDcols = syms]
# Keep at most 10 per date using momentum as the ranking signal
lim <- limit_positions(selection_df = sel_mask, max_positions = 10L,
ranking_signal = mom12, verbose = FALSE)
head(lim)
# }
Run the code above in your browser using DataLab