Skip to contents

ledgr_experiment() bundles a sealed snapshot, strategy, features, opening state, and execution options into the experiment-first public object used by the v0.1.7 workflow. The constructor validates shape only; it does not run a strategy or write run artifacts.

Usage

ledgr_experiment(
  snapshot,
  strategy,
  features = list(),
  opening = ledgr_opening(cash = 1e+05),
  universe = NULL,
  fill_model = NULL,
  persist_features = TRUE,
  execution_mode = "audit_log"
)

Arguments

snapshot

A sealed ledgr_snapshot.

strategy

A function with signature function(ctx, params).

features

List of ledgr_indicator objects, a ledgr_feature_map, or a function with signature function(params) returning one of those forms at run time.

opening

A ledgr_opening object.

universe

Character vector of instrument IDs, or NULL for all instruments in the snapshot.

fill_model

Fill model config. NULL uses ledgr's default next-open model with zero spread and zero fixed commission. For fill_model$spread_bps, ledgr applies the full value on each fill leg: buys fill at open * (1 + spread_bps / 10000) and sells fill at open * (1 - spread_bps / 10000). A buy/sell round trip therefore costs approximately 2 * spread_bps basis points before commissions.

persist_features

Logical scalar.

execution_mode

Execution mode ("audit_log" or "db_live").

Value

A ledgr_experiment object.

Articles

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

Durable experiment stores: vignette("experiment-store", package = "ledgr") system.file("doc", "experiment-store.html", package = "ledgr")

Reproducibility model: vignette("reproducibility", package = "ledgr") system.file("doc", "reproducibility.html", package = "ledgr")

Examples

bars <- data.frame(
  ts_utc = as.POSIXct("2020-01-01", tz = "UTC") + 86400 * 0:2,
  instrument_id = "AAA",
  open = c(100, 101, 102),
  high = c(101, 102, 103),
  low = c(99, 100, 101),
  close = c(100, 101, 102),
  volume = 1000
)
snapshot <- ledgr_snapshot_from_df(bars)
strategy <- function(ctx, params) {
  stats::setNames(rep(0, length(ctx$universe)), ctx$universe)
}
exp <- ledgr_experiment(snapshot, strategy)
inherits(exp, "ledgr_experiment")
#> [1] TRUE
ledgr_snapshot_close(snapshot)