Skip to contents

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

Usage

target_rebalance(weights, ctx, equity_fraction = 1)

Arguments

weights

A ledgr_weights object.

ctx

ledgr strategy context.

equity_fraction

Fraction of current equity to allocate, between 0 and 1.

Value

A full-universe ledgr_target object.

Details

Warning and error classes:

  • ledgr_invalid_target_price when a selected instrument has missing, non-finite, or non-positive close price;

  • ledgr_negative_weights for negative weights;

  • ledgr_levered_weights when sum(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