ExecutionContext#
API documentation for tradeexecutor.strategy.execution_context.ExecutionContext Python class in Trading Strategy framework.
- class ExecutionContext[source]#
Bases:
object
Information about the strategy execution environment.
Execution context helps the strategy to decide different code paths, whether we are doing backtesting, live trading and what is the target Trading Strategy engine version.
This is passed to create_trading_universe and other functions. they can determine and take action based the mode of strategy execution. For example, we may load pair and candle data differently in live trading. See
mode
.Some function signatures have been made better, but we still need to maintain backwards compatibility, see
engine_version
.We also pass the Python profiler hook
timed_task_context_manager
.
Example how to create for backtests:
from tradeexecutor.strategy.execution_context import ExecutionContext, ExecutionMode execution_context = ExecutionContext( mode=ExecutionMode.backtesting, )
See also
unit_test_execution_context
notebook_execution_context
- __init__(mode, timed_task_context_manager=<function timed_task>, engine_version=None, parameters=None, grid_search=False, optimiser=False, jupyter=False, progress_bars=True, force_visualisation=False)#
- Parameters:
mode (ExecutionMode) –
timed_task_context_manager (Callable) –
engine_version (str) –
parameters (tradeexecutor.strategy.parameters.StrategyParameters | None) –
grid_search (bool) –
optimiser (bool) –
jupyter (bool) –
progress_bars (bool) –
force_visualisation (bool) –
- Return type:
None
Methods
__init__
(mode[, timed_task_context_manager, ...])Should backtest spend time to draw custom visualisations.
is_version_greater_or_equal_than
(major, ...)Check that we are runing engine as the minimum required version.
Attributes
What is the current mode of the execution.
Python context manager for timed tasks.
What TS engine the strategy is using.
Strategy parameters
Is this backtest run part of a grid search group
Is this backtest run part of a optimiser
Are we running inside Jupyter notebook.
Render tqdm progress bars when running
Force collection of visualisation and draw data during grid search and optimisation.
Are we doing live trading.
unit_test
- mode: ExecutionMode#
What is the current mode of the execution.
- timed_task_context_manager: Callable#
Python context manager for timed tasks.
Functions can use this context manager to add them to the tracing. Used for profiling the strategy code run-time performance.
Set default to
tradeexecutor.utils.timer.timed_task()
. which logs task duration using logging.INFO level.
- parameters: tradeexecutor.strategy.parameters.StrategyParameters | None#
Strategy parameters
For backtesting/grid search cycle.
v0.4 only
- jupyter: bool#
Are we running inside Jupyter notebook.
We might have HTML widgets available like HTML progress bar
We have interactive prompts available
- progress_bars: bool#
Render tqdm progress bars when running
Disabled in child worker process context.
- force_visualisation: bool#
Force collection of visualisation and draw data during grid search and optimisation.
Slows down the process a bit. Note that changing this parameter means that you need to manually deleted previous cached results, as this is stored as the part of the backtest state.
See perform_optimisation(draw_visualisation) argument.
- is_version_greater_or_equal_than(major, minor, patch)[source]#
Check that we are runing engine as the minimum required version.
- has_visualisation()[source]#
Should backtest spend time to draw custom visualisations.
By default, disabled for the grid search/optimiser for the speed
- Return type:
- __init__(mode, timed_task_context_manager=<function timed_task>, engine_version=None, parameters=None, grid_search=False, optimiser=False, jupyter=False, progress_bars=True, force_visualisation=False)#
- Parameters:
mode (ExecutionMode) –
timed_task_context_manager (Callable) –
engine_version (str) –
parameters (tradeexecutor.strategy.parameters.StrategyParameters | None) –
grid_search (bool) –
optimiser (bool) –
jupyter (bool) –
progress_bars (bool) –
force_visualisation (bool) –
- Return type:
None