Skip to contents

ledgr_precompute_features() resolves the feature definitions required by a parameter grid, deduplicates identical indicators by fingerprint, computes their series once against a sealed snapshot, and returns a typed payload for future sweep execution.

Usage

ledgr_precompute_features(exp, param_grid, start = NULL, end = NULL)

Arguments

exp

A ledgr_experiment object.

param_grid

An ordinary rectangular data frame, a ledgr_strategy_grid, or a ledgr_executable_grid.

start

Optional scoring-range start. Defaults to the experiment's opening date, or to the snapshot start when the opening is undated.

end

Optional scoring-range end. Defaults to the snapshot end.

Value

A ledgr_precomputed_features object.

Details

The payload is validated by ledgr_sweep() against the snapshot hash, universe, scoring range, causal-history identity, feature engine version, grid labels, and resolved feature fingerprints. Use it for larger exploratory grids; ledgr_sweep() warns when more than 20 combinations run without precomputed features.

For an availability-aware experiment the payload is computed through the same causal history substrate, history policy and calculation bounds as the experiment's runs and sweeps: feature state starts at the data start (the first session of the snapshot), whatever the scoring start. The payload records its causal axis (data start, first calculated session, cutoff and session stamps). A sweep reuses it only when that axis, the cutoff, the history policy, the snapshot and every candidate's feature identity match exactly; otherwise it refuses before any candidate runs. A dense payload never serves an availability sweep, nor the reverse.

Dense experiments are unchanged: their feature state starts at the scoring start, bars before start are not read, and a sweep refuses a dense payload whose scoring start differs from its own.

Articles

Exploratory sweeps and promotion: vignette("sweeps", package = "ledgr") system.file("doc", "sweeps.html", package = "ledgr")

Examples

bars <- data.frame(
  ts_utc = as.POSIXct("2020-01-01", tz = "UTC") + 86400 * 0:4,
  instrument_id = "AAA",
  open = 100:104,
  high = 101:105,
  low = 99:103,
  close = 100:104,
  volume = 1000
)
snapshot <- ledgr_snapshot_from_df(bars)
strategy <- function(ctx, params) ctx$flat()
exp <- ledgr_experiment(snapshot, strategy, features = list(ledgr_ind_sma(2)), cost_model = ledgr_cost_zero())
grid <- data.frame(qty = c(1, 2))
features <- ledgr_precompute_features(exp, grid)
print(features)
#> ledgr_precomputed_features
#> ===========================
#> Snapshot:   snapshot_20261027_174427_9b39
#> Candidates: 2
#> Features:   1
#> Universe:   AAA
#> Scoring:    2020-01-01T00:00:00Z to 2020-01-05T00:00:00Z
ledgr_snapshot_close(snapshot)