Skip to contents

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"))

Arguments

signal

A ledgr_signal object.

n

Number of instruments to select.

partial

Whether a short selection warns ("warn", the default) or is accepted silently ("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_selection for the classed object returned when every signal value is missing;

  • ledgr_partial_selection for the warning emitted when fewer than n eligible, non-missing values are available under partial = "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