Skip to contents

ledgr_selection() creates a named logical vector for strategy helper pipelines. Selections are intermediate objects; strategies must not return them directly.

Usage

ledgr_selection(
  x,
  universe = NULL,
  origin = NULL,
  ...,
  missing = c("error", "exclude")
)

Arguments

x

Named logical vector where TRUE means selected, or a pulse context.

universe

Optional universe used to reject extra instrument names.

origin

Optional helper/source label for printing.

...

In context mode, at most one named ids or where payload.

missing

In context mode, whether missing decisions for eligible instruments fail ("error", the default) or count as not selected ("exclude"). A subsequent rebalance targets excluded held members to zero; use ctx$hold() when the intended action is to preserve positions. This is a decision policy, unlike ctx$idx(id, missing = "na"), which controls a missing instrument lookup.

Value

A ledgr_selection object.

Details

In context mode, the selection covers the whole decision axis and is FALSE for every ineligible instrument, whatever the payload: no payload selects every eligible instrument, where decides eligible instruments only, and ids naming an ineligible instrument leave it unselected.

Articles

Strategy helper pipelines: vignette("strategy-development", package = "ledgr") system.file("doc", "strategy-development.html", package = "ledgr")

Examples

ledgr_selection(c(AAA = TRUE, BBB = FALSE), universe = c("AAA", "BBB"))
#> <ledgr_selection> [2 assets]
#> 1 selected
#>   AAA   BBB 
#>  TRUE FALSE 
ctx <- structure(
  list(
    universe = c("AAA", "BBB"),
    vec = list(id = c("AAA", "BBB")),
    availability_active = FALSE
  ),
  class = "ledgr_pulse_context"
)
ledgr_selection(ctx, where = c(TRUE, NA), missing = "exclude")
#> <ledgr_selection> [2 assets]
#> 1 selected
#>   AAA   BBB 
#>  TRUE FALSE