Skip to content

Experiment


class backtide.backtest.experiment.Experiment(config=None, strategies=None, indicators=None)[source]

Configure and run one historical backtest experiment.

Performs the full pipeline end-to-end:

  1. Resolves and downloads the required market data (skipped if already present in the database).
  2. Computes indicators over the entire dataset.
  3. Runs every strategy in parallel. Each strategy has its own independent portfolio, order book and equity curve.
  4. Persists the results into the database.

Read more in the user guide.

Parameters

config : ExperimentConfig | None, default=None

Serializable data, portfolio, execution, engine, and metric settings. Uses defaults when omitted.

strategies : str | object | dict[str, object] | list | None, default=None
Runtime strategies for this experiment. Accepts stored names, strategy instances, explicit dict[name, instance] mappings, or a list mixing those forms. When omitted, uses the stored names in config.

indicators : str | object | dict[str, object] | list | None, default=None
Runtime indicators to compute in addition to strategy-required indicators. Accepts the same forms as strategies. When omitted, uses the stored names in config.


Example

>>> from backtide import DataExpConfig, Experiment, ExperimentConfig
>>> from backtide.strategies import BuyAndHold

>>> config = ExperimentConfig(
...     data=DataExpConfig(
...         symbols=["AAPL", "MSFT"],
...         interval="1d",
...     )
... )
>>> result = Experiment(config, strategies=[BuyAndHold()]).run()
>>> print(result)

ExperimentResult(id="bc4e9165fe114ceb", name="a413448d", status="success", n_strategies=1)


Methods

run Run the configured experiment and return its persisted result.


method run(verbose=True, progress_callback=None)[source]

Run the configured experiment and return its persisted result.

Parameters

verbose : bool, default=True

Show determinate simulation progress in the terminal.

progress_callback : Callable[[int, int], None] | None, default=None
Receive throttled (completed, total) simulation-step updates. A step is one timeline bar processed by one strategy.

Returns

ExperimentResult

Persisted result for every configured strategy.