Construct full target quantities from a selection
Source:R/strategy-helpers.R
ledgr_target_quantity.Rdledgr_target_quantity() converts a selection into a full-universe
ledgr_target that holds the same fixed quantity of every selected
instrument. Selected eligible instruments get qty; every other eligible
instrument gets zero. Use it for rules such as "hold 10 shares of each instrument that
passes the condition"; use ledgr_weight_equal() and
ledgr_target_rebalance() instead when positions should be sized from
account equity.
Details
Missing decisions are settled by the selection, not here: build the
selection with ledgr_selection(ctx, where = ..., missing = "exclude") when
a missing value, such as a feature still in warmup, should mean "not
selected".
In an availability-aware run, every ineligible instrument, a held nonmember
or a target-restricted member, keeps its current quantity, exactly as
ledgr_target_rebalance() preserves it. The selection may name any instrument
on the decision axis, but may select eligible instruments only.
Error class: ledgr_invalid_strategy_helper when selection is not a
ledgr_selection, names an instrument outside the decision axis, selects
an ineligible instrument, or
when qty is not one finite, non-negative number. Negative quantities stay
refused until short-selling semantics are defined.
Articles
Strategy helper pipelines:
vignette("strategy-development", package = "ledgr")
system.file("doc", "strategy-development.html", package = "ledgr")
Examples
selection <- ledgr_selection(c(AAA = TRUE, BBB = FALSE),
universe = c("AAA", "BBB"))
ctx <- list(universe = c("AAA", "BBB"))
ledgr_target_quantity(selection, ctx, qty = 10)
#> <ledgr_target> [2 assets]
#> non-NA: 2/2
#> AAA BBB
#> 10 0