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_indicatorobjects, aledgr_feature_map, or a function with signaturefunction(params)returning one of those forms at run time.- opening
A
ledgr_openingobject.- universe
Character vector of instrument IDs, or
NULLfor all instruments in the snapshot.- fill_model
Fill model config.
NULLuses ledgr's default next-open model with zero spread and zero fixed commission. Forfill_model$spread_bps, ledgr applies the full value on each fill leg: buys fill atopen * (1 + spread_bps / 10000)and sells fill atopen * (1 - spread_bps / 10000). A buy/sell round trip therefore costs approximately2 * spread_bpsbasis points before commissions.- persist_features
Logical scalar.
- execution_mode
Execution mode (
"audit_log"or"db_live").
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)