Skip to contents

ledgr_feature_contract_check() joins declared feature contracts to the actual per-instrument bar counts in a sealed snapshot. It is a pre-run inspection helper: it tells you whether each feature can become usable for each instrument in this snapshot. It does not compute feature values and does not mutate the snapshot.

Usage

ledgr_feature_contract_check(snapshot, features)

Arguments

snapshot

A sealed ledgr_snapshot.

features

A ledgr_feature_map, a list of ledgr_indicator objects, or one ledgr_indicator.

Value

A tibble with one row per (instrument_id, feature_id) pair. It includes alias, instrument_id, feature_id, source, requires_bars, stable_after, available_bars, and warmup_achievable. warmup_achievable is TRUE when the instrument has at least stable_after bars.

Details

Feature factories of the form function(params) are intentionally rejected here because the helper cannot know which concrete parameter set to use. Materialize the factory first, then pass the resulting indicators or feature map. The error class is ledgr_feature_factory_requires_params.

Articles

Indicators, feature IDs, and pulse feature views:

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

Examples

bars <- data.frame(
  ts_utc = ledgr_utc("2020-01-01") + 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)
features <- list(ledgr_ind_returns(3), ledgr_ind_sma(10))
ledgr_feature_contract_check(snapshot, features)
#> # A tibble: 2 × 8
#>   alias instrument_id feature_id source requires_bars stable_after
#>   <chr> <chr>         <chr>      <chr>          <int>        <int>
#> 1 NA    AAA           return_3   ledgr              4            4
#> 2 NA    AAA           sma_10     ledgr             10           10
#> # ℹ 2 more variables: available_bars <int>, warmup_achievable <lgl>
ledgr_snapshot_close(snapshot)