2024-11-15 21:13:19 +01:00
|
|
|
# BackTestController
|
|
|
|
|
|
|
|
|
|
## Table of Contents
|
|
|
|
|
- [BackTestController](#backtest_controller.back_test_controller)
|
|
|
|
|
- [backtest_engine](#backtest_controller.backtest_engine)
|
|
|
|
|
- [add_tasks](#backtest_controller.add_tasks)
|
|
|
|
|
- [set_parties](#backtest_controller.set_parties)
|
|
|
|
|
- [parties](#backtest_controller.parties)
|
|
|
|
|
- [control](#backtest_controller.control)
|
|
|
|
|
- [stop_backtesting](#backtest_controller.stop_backtesting)
|
|
|
|
|
- [wait](#backtest_controller.wait)
|
|
|
|
|
- [abort](#backtest_controller.abort)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="backtest_controller.back_test_controller"></a>
|
|
|
|
|
### BackTestController
|
2024-11-13 04:29:37 +01:00
|
|
|
```python
|
2024-11-15 21:13:19 +01:00
|
|
|
class BackTestController
|
2024-11-13 04:29:37 +01:00
|
|
|
```
|
|
|
|
|
The controller for the backtesting engine.
|
2024-11-15 21:13:19 +01:00
|
|
|
It also acts as a synchronizer for running multiple strategies (tasks) using a threading.Barrier primitive.
|
2024-11-13 04:29:37 +01:00
|
|
|
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.
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
#### 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 |
|
2024-11-13 04:29:37 +01:00
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.backtest_engine"></a>
|
|
|
|
|
#### backtest_engine
|
2024-11-13 04:29:37 +01:00
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def backtest_engine()
|
|
|
|
|
```
|
|
|
|
|
Returns the backtest engine
|
|
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.add_tasks"></a>
|
|
|
|
|
#### add_tasks
|
2024-11-13 04:29:37 +01:00
|
|
|
```python
|
|
|
|
|
def add_tasks(*tasks: Task)
|
|
|
|
|
```
|
2024-11-15 21:13:19 +01:00
|
|
|
Adds a task to the tasks list
|
2024-11-13 04:29:37 +01:00
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.set_parties"></a>
|
|
|
|
|
#### set_parties
|
2024-11-13 04:29:37 +01:00
|
|
|
```python
|
|
|
|
|
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.
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
#### Parameters:
|
|
|
|
|
| Name | Type | Description |
|
|
|
|
|
|-----------|-------|---------------------------------------------|
|
|
|
|
|
| `parties` | `int` | The number of parties to set the barrier to |
|
2024-11-13 04:29:37 +01:00
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.parties"></a>
|
2024-11-13 04:29:37 +01:00
|
|
|
#### parties
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def parties()
|
|
|
|
|
```
|
|
|
|
|
Returns the number of parties for the barrier
|
|
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.control"></a>
|
2024-11-13 04:29:37 +01:00
|
|
|
#### control
|
|
|
|
|
```python
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.stop_backtesting"></a>
|
|
|
|
|
#### stop_backtesting
|
2024-11-13 04:29:37 +01:00
|
|
|
```python
|
|
|
|
|
def stop_backtesting()
|
|
|
|
|
```
|
|
|
|
|
Stop the backtester, and shutdown the executor
|
|
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.wait"></a>
|
2024-11-13 04:29:37 +01:00
|
|
|
#### wait
|
|
|
|
|
```python
|
|
|
|
|
def wait()
|
|
|
|
|
```
|
|
|
|
|
Called by individual tasks to indicate completion of their cycle
|
|
|
|
|
|
|
|
|
|
|
2024-11-15 21:13:19 +01:00
|
|
|
<a id="backtest_controller.abort"></a>
|
2024-11-13 04:29:37 +01:00
|
|
|
#### abort
|
|
|
|
|
```python
|
|
|
|
|
def abort()
|
|
|
|
|
```
|
|
|
|
|
Aborts the barrier
|