Skip to content

Backtest Engine for Trading Evaluation #65

Description

@quantspub

Problem / Motivation

As the bot evolves into a full-fledged ML-driven trading system, the need for a standardized backtest engine looks quite critical.

Currently, the backtesting logic is implemented through ad-hoc scripts (e.g., simulate_model) and custom performance functions (simulated_trade_performance). While functional, this approach lacks:

  • Consistency across different strategies and configurations
  • Reusability for rapid experimentation and validation
  • Support for live vs simulated parity, a must for bridging to live trading
  • Extensibility to support risk metrics, multiple assets, slippage, commission, and model retraining over time

For ML-based systems, where models are trained on past data and evaluated in a forward-looking manner (e.g., walk-forward), a formal backtesting engine ensures fair, repeatable, and accurate performance estimation.

PS: I think we can use VectorBT as the backend for this.

Objective

Design and implement a modular, strategy-agnostic Backtest Engine that:

  • Accepts configurable parameters (thresholds, signal columns, etc.)
  • Supports rolling retraining / evaluation of ML models
  • Evaluates strategies using both price and derived ML signals
  • Produces detailed metrics (profit, Sharpe, win-rate, drawdown, etc.)
  • Can be extended to support VectorBT, CCXT, and live execution parity

Structure

  • Backtest Inputs:

    • DataFrame with OHLCV and model predictions
    • Strategy config (buy/sell thresholds, retrain frequency, etc.)
    • Evaluation period split (train/test windows)
  • Backtest Outputs:

    • Trade logs
    • Summary metrics

Evaluation Metrics to Include

  • Net profit / % profit
  • Sharpe ratio / Sortino ratio
  • Max drawdown
  • Number of trades
  • Win rate
  • Profit factor
  • Profit per month / trade

📌 Tasks

  • Define base BacktestEngine and interface
  • Migrate simulated_trade_performance() into engine-compatible module
  • Build ThresholdStrategy and MLBasedStrategy
  • Add metrics computation using vectorbt or bt as backend
  • Add support for multiple symbols
  • Add support for strategy retraining
  • Document engine usage in README.md

If anyone has prior experience with backtesting engines (e.g., Zipline, Backtrader, VectorBT, bt), feel free to share thoughts, patterns, or contribute prototypes. Design suggestions are welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions