Skip to contents

ledgr_feature_map() bundles user-facing aliases with ledgr indicator definitions. The map is an authoring convenience: experiments register the underlying indicators, while strategies can later use the aliases for pulse-time feature lookup.

Usage

ledgr_feature_map(...)

# S3 method for class 'ledgr_feature_map'
print(x, ...)

Arguments

...

For ledgr_feature_map(), named ledgr_indicator objects. Names are strategy-facing aliases. For the print method, unused.

x

A ledgr_feature_map object.

Value

A ledgr_feature_map object.

The input object, invisibly.

Details

A feature map is also accepted anywhere features = list(...) is accepted. Plain lists remain valid; use a feature map when readable aliases make strategy code clearer. The map is validated at construction time, and ledgr_feature_id() returns a named character vector keyed by alias. Inside a strategy body, ctx$features(instrument_id, feature_map) returns a named numeric vector keyed by the feature-map aliases. Use passed_warmup() on that vector before applying rules that require all mapped values to be finite.

Articles

Feature maps are taught in the strategy-development article:

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

Indicator configuration is covered in:

vignette("indicators", package = "ledgr") system.file("doc", "indicators.html", package = "ledgr")

Examples

features <- ledgr_feature_map(
  ret_5 = ledgr_ind_returns(5),
  sma_10 = ledgr_ind_sma(10)
)

ledgr_feature_id(features)
#>      ret_5     sma_10 
#> "return_5"   "sma_10" 

strategy <- function(ctx, params) {
  targets <- ctx$flat()
  for (id in ctx$universe) {
    x <- ctx$features(id, features)
    if (passed_warmup(x) && x[["ret_5"]] > params$min_return) {
      targets[id] <- params$qty
    }
  }
  targets
}