Skip to main content

TradingEnvironment

dataclass
Container for all trading components.

TradingEnvironment.attach_to_strategy

Attach all components to a strategy.

EnvironmentBuilder

Builder for creating trading environments with sensible defaults. Record the ids and starting equity; every component stays unset until build(). Parameters

EnvironmentBuilder.with_datafeed

Use datafeed instead of the default local one. build() then requires a matching resolver from with_resolver.

EnvironmentBuilder.with_resolver

Use resolver instead of the default local resolver registry.

EnvironmentBuilder.with_broker

Use broker instead of the default SimulationBroker.

EnvironmentBuilder.with_portfolio

Use portfolio instead of one built from initial_equity. Its own fee calculator stands: with_fee_calculator is then ignored.

EnvironmentBuilder.with_pulse_index

Use pulse_index as the clock, in preference to any calendar. build() still derives the underlyings’ common settlements when with_datetimes is absent; only the resulting value goes unused.

EnvironmentBuilder.with_datetimes

Pulse on datetimes instead of on the underlyings’ common settlements. Copied, and ignored if with_pulse_index supplies a clock of its own. Mutually exclusive with with_date_range: an explicit calendar is already bounded.

EnvironmentBuilder.with_date_range

Bound the derived calendar, inclusive at both ends. The bounds go to pdc’s available_settlements, so the calendar is bisected rather than derived whole and trimmed. Mutually exclusive with with_datetimes, and ignored if with_pulse_index supplies a clock of its own. Parameters

EnvironmentBuilder.with_fee_calculator

Apply fee_calculator to the default Portfolio built by build(). Ignored if a portfolio was already supplied via with_portfolio.

EnvironmentBuilder.build

Build the trading environment with defaults for missing components.

ExecutionResult

dataclass
Result of a strategy execution.

StrategyExecutor

Bases: ABC Abstract base class for strategy executors.

StrategyExecutor.execute

abstractmethod
Execute a strategy in the given environment.

SequentialBatchExecutor

Bases: StrategyExecutor Executes multiple strategies in sequence.

SequentialBatchExecutor.execute

Execute every strategy in order, each against its own environment. A strategy that raises aborts the batch and the exception propagates. Collecting it onto the result instead is what the removed stop_on_error=False did, and it left a sweep looking finished until strategy.stats raised.

AllassoTradeMachine

The engine that runs strategies against their trading environments. Parameters

AllassoTradeMachine.sequential

classmethod
Create ATM for sequential strategy execution.

AllassoTradeMachine.run

Run the strategy(ies) against the given environments.

warm_readers

Open every snapshot reader the calendar will touch, before the first pulse. pdc opens a day file on first request, so an unwarmed run pays for the whole tree one file at a time inside the loop. get_reader caches, so this only front-loads that work: warming a datafeed twice (a sweep builds one environment per strategy) costs a dict lookup per pulse. Providers that are not pdc’s local ones have nothing to open and are skipped, as is an underlying whose tree the provider does not cover (a futures-only root has no option snapshots); those keep the lazy path.

run_sequentially

Run strategies one after another, each in its own trading environment. One EnvironmentBuilder per strategy, built from that strategy’s own underlying_id, so a sweep is just a list of strategies here. Every strategy gets its own portfolio, broker and pulse index; the datafeed and resolver are shared, which is what makes the warmed readers worth paying for once. The pulse calendar is the underlyings’ common settlements, optionally bounded by start_datetime / end_datetime, which are handed to pdc’s available_settlements and are inclusive at both ends. datetimes replaces that calendar outright instead, so it cannot be combined with the bounds. Parameters Raises Returns
Last modified on November 4, 2026