UniverseModel#

API documentation for tradeexecutor.strategy.universe_model.UniverseModel Python class in Trading Strategy framework.

class UniverseModel[source]#

Bases: ABC

Create and manage trade universe.

On a live execution, the trade universe is reconstructor for the every tick, by refreshing the trading data from the server.

__init__()#

Methods

__init__()

check_data_age(ts, universe, ...)

Check if our data is up-to-date and we do not have issues with feeds.

construct_universe(ts, mode, universe_options)

On each strategy tick, refresh/recreate the trading universe for the strategy.

preload_universe(universe_options[, ...])

Triggered before backtesting execution.

preload_universe(universe_options, execution_context=None)[source]#

Triggered before backtesting execution.

  • Load all datasets with progress bar display

  • Data is saved in FS cache

  • Not triggered in live trading, as universe changes between cycles

Parameters:
Return type:

StrategyExecutionUniverse

abstract construct_universe(ts, mode, universe_options)[source]#

On each strategy tick, refresh/recreate the trading universe for the strategy.

This is called in mainloop before the strategy tick. It needs to download any data updates since the last tick.

Parameters:
  • mode (ExecutionMode) – Are we live trading or backtesting.

  • universe_options (UniverseOptions) – Override any parameters for universe data. Most useful for making stop loss data checks less frequent, speeding up the backtesting.

  • ts (datetime) –

Return type:

StrategyExecutionUniverse

check_data_age(ts, universe, best_before_duration)[source]#

Check if our data is up-to-date and we do not have issues with feeds.

Ensure we do not try to execute live trades with stale data.

Raises:

DataTooOld – in the case data is too old to execute.

Parameters: