target_rebalance() converts long-only weights into a full-universe
ledgr_target. It uses current pulse equity and current close prices at
decision time; fills still occur at the next open, so small drift between
decision-time sizing and fill-time value is expected. Share quantities are
floored to whole numbers with floor(weight * equity_fraction * equity / close_price).
Details
Warning and error classes:
ledgr_invalid_target_pricewhen a selected instrument has missing, non-finite, or non-positive close price;ledgr_negative_weightsfor negative weights;ledgr_levered_weightswhensum(abs(weights)) > 1.
Articles
Strategy helper pipelines:
vignette("strategy-development", package = "ledgr")
system.file("doc", "strategy-development.html", package = "ledgr")
Examples
weights <- ledgr_weights(c(AAA = 0.5, BBB = 0.5), universe = c("AAA", "BBB"))
ctx <- list(
universe = c("AAA", "BBB"),
equity = 1000,
close = function(id) c(AAA = 50, BBB = 100)[[id]]
)
target_rebalance(weights, ctx, equity_fraction = 0.5)
#> <ledgr_target> [2 assets]
#> non-NA: 2/2
#> AAA BBB
#> 5 2