ledgr_select_top_n() selects the highest non-missing signal values among
eligible instruments: a signal built from a context marks ineligible
instruments in its eligible attribute, and they are never selected or
counted. Missing values are ignored. Ties are broken deterministically by
instrument ID in C-locale (byte) order, whatever the session collation. The
result covers the signal's whole axis. If no values are usable, the function returns a classed empty selection,
all FALSE, without warning; it keeps the signal origin and flows through
ledgr_weight_equal() and ledgr_target_rebalance() to a target that keeps
ineligible holdings and zeroes the rest.
Usage
ledgr_select_top_n(signal, n, partial = c("warn", "allow"))Value
A ledgr_selection object. When all signal values are missing, the
object also inherits from ledgr_empty_selection.
Details
Selection and warning classes:
ledgr_empty_selectionfor the classed object returned when every signal value is missing;ledgr_partial_selectionfor the warning emitted when fewer thanneligible, non-missing values are available underpartial = "warn".
Articles
Strategy helper pipelines:
vignette("strategy-development", package = "ledgr")
system.file("doc", "strategy-development.html", package = "ledgr")
Examples
signal <- ledgr_signal(c(AAA = 0.03, BBB = NA, CCC = 0.01), origin = "return_5")
ledgr_select_top_n(signal, n = 1)
#> <ledgr_selection> [3 assets]
#> origin: return_5
#> 1 selected
#> AAA BBB CCC
#> TRUE FALSE FALSE
ledgr_select_top_n(signal, n = 3, partial = "allow")
#> <ledgr_selection> [3 assets]
#> origin: return_5
#> 2 selected
#> AAA BBB CCC
#> TRUE FALSE TRUE