Skip to contents

Releases any open DuckDB connection held by a ledgr_backtest object and checkpoints a durable run file when possible. Completed run artifacts are already durable when ledgr_run() returns; close(bt) is resource management for explicit opens, lazy result cursors, tests, and long sessions. The underlying DuckDB file is not deleted.

Usage

# S3 method for class 'ledgr_backtest'
close(con, ...)

Arguments

con

A ledgr_backtest object.

...

Unused.

Value

The input object, invisibly.

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
)
strategy <- function(ctx, params) {
  targets <- ctx$flat()
  targets["AAA"] <- 1
  targets
}
bt <- ledgr_backtest(data = bars, strategy = strategy, initial_cash = 1000)
close(bt)