3.0 KiB
BackTestController
Table of Contents
- BackTestController
- backtest_engine
- add_tasks
- set_parties
- parties
- control
- stop_backtesting
- wait
- abort
BackTestController
class BackTestController
The controller for the backtesting engine. It also acts as a synchronizer for running multiple strategies (tasks) using a threading.Barrier primitive. It handles the updating of open positions and close them when necessary. It handles the iterator for the backtesting engine and handles it movement in time by moving it to the next time step.
Attributes:
| Name | Type | Description |
|---|---|---|
_instance |
BackTestController |
The instance of the controller |
config |
Config |
The configuration for the backtesting engine |
tasks |
list[Task] |
The tasks that are being run |
barrier |
Barrier |
The barrier for synchronizing the tasks |
backtest_engine
@property
def backtest_engine()
Returns the backtest engine
add_tasks
def add_tasks(*tasks: Task)
Adds a task to the tasks list
set_parties
def set_parties(*, parties: int)
Sets the number of parties for the barrier. The barrier will wait for the number of parties to reach the barrier. This has to be done here as it can be impossible to know the eventual number of parties to set the barrier to during initialization.
Parameters:
| Name | Type | Description |
|---|---|---|
parties |
int |
The number of parties to set the barrier to |
parties
@property
def parties()
Returns the number of parties for the barrier
control
async def control()
The backtest controller. It controls the backtesting engine and the tasks that are being run. It acts as a synchronizer for the tasks and the backtesting engine.
stop_backtesting
def stop_backtesting()
Stop the backtester, and shutdown the executor
wait
def wait()
Called by individual tasks to indicate completion of their cycle
abort
def abort()
Aborts the barrier