turtle_quant_1.backtesting.engine¶
turtle_quant_1.backtesting.engine
¶
Backtesting engine for strategy evaluation.
BacktestingEngine
¶
BacktestingEngine(
strategy_engine: BaseStrategyEngine,
symbols: list[str] = BACKTESTING_SYMBOLS,
initial_capital: float = 0.0,
max_history_days: int = MAX_HISTORY_DAYS,
max_lookback_days: int = BACKTESTING_MAX_LOOKBACK_DAYS,
max_lookforward_days: int = BACKTESTING_MAX_LOOKFORWARD_DAYS,
tick_interval: CandleUnit = "4H",
event_interval: CandleUnit = "30M",
)
Backtesting engine for evaluating trading strategies.
Initialize the backtesting engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy_engine
|
BaseStrategyEngine
|
The strategy engine to use for generating signals. |
required |
symbols
|
list[str]
|
List of symbols to backtest. If None, uses BACKTESTING_SYMBOLS. |
BACKTESTING_SYMBOLS
|
initial_capital
|
float
|
Starting capital for the portfolio (default: 0.0). |
0.0
|
max_history_days
|
int
|
Maximum days of history to download. |
MAX_HISTORY_DAYS
|
max_lookback_days
|
int
|
Days of data to use for strategy signals. |
BACKTESTING_MAX_LOOKBACK_DAYS
|
max_lookforward_days
|
int
|
Days of data to simulate trading on. |
BACKTESTING_MAX_LOOKFORWARD_DAYS
|
tick_interval
|
CandleUnit
|
Duration of one tick window as a candle-unit string (e.g. "4H"). Passed through to TradingEngine to determine how many candle events are replayed per tick. |
'4H'
|
event_interval
|
CandleUnit
|
Duration of one event window as a candle-unit string (e.g. "30M"). Passed through to TradingEngine to determine how many candle events are replayed per event. |
'30M'
|
Source code in src/turtle_quant_1/backtesting/engine.py
get_metrics
¶
Calculate metrics for the portfolio performance.
NOTE: This is currently a wrapper around quantstats metrics. TODO: Implement our own metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark
|
str
|
Benchmark symbol to compare against (default: SPY) |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary containing quantstats metrics |
Source code in src/turtle_quant_1/backtesting/engine.py
run_backtest
¶
run_backtest() -> TestCaseResults
Run the backtesting simulation.
Returns:
| Type | Description |
|---|---|
TestCaseResults
|
BacktestingResults with backtesting results. |
Source code in src/turtle_quant_1/backtesting/engine.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |