Backtest
Backtest execution logic for the dashboard.
Provides the request model, job tracking, and execution function for running backtests from the dashboard UI.
running_jobs = {}
module-attribute
RTYPE_TO_BAR_PERIOD = {32: 'SECOND', 33: 'MINUTE', 34: 'HOUR', 35: 'DAY'}
module-attribute
BacktestRequest
Bases: BaseModel
Request model for backtest execution.
Attributes:
| Name | Type | Description |
|---|---|---|
strategy |
str
|
Name of the strategy class to run. |
strategy_params |
dict
|
Dictionary of parameter overrides for the strategy. |
symbols |
list[str]
|
List of instrument symbols to trade. |
rtype |
int
|
Bar period rtype code (32=second, 33=minute, 34=hour, 35=day). |
publisher_id |
int
|
Publisher ID for data source selection. |
start_date |
str | None
|
Optional start date in YYYY-MM-DD format. |
end_date |
str | None
|
Optional end date in YYYY-MM-DD format. |
Source code in src/onesecondtrader/dashboard/backtest.py
deserialize_params(params, param_specs)
Deserialize strategy parameters, converting enum strings to enum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dictionary of parameter names to values from the request. |
required |
param_specs
|
dict
|
Dictionary of parameter names to ParamSpec instances. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with enum strings converted to their enum values. |
Source code in src/onesecondtrader/dashboard/backtest.py
run_backtest(request, run_id)
Execute a backtest in a background task.
Configures and runs an Orchestrator with the specified strategy, symbols, and data source. Updates running_jobs with status during execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
BacktestRequest
|
Backtest configuration from the API request. |
required |
run_id
|
str
|
Unique identifier for tracking this backtest job. |
required |
Source code in src/onesecondtrader/dashboard/backtest.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |