← Back to Wiki Index

Backtesting Engine

Detailed documentation of the backtesting system: methodology, assumptions, and implementation details.

Overview

The backtesting engine is built in Python using pandas and numpy for efficient data processing. It simulates trading strategies on historical data to evaluate their performance before live deployment.

Key Features

  • Vectorized backtesting for fast execution
  • Walk-forward optimization
  • Out-of-sample testing
  • Realistic transaction costs and slippage
  • Multiple performance metrics
  • Risk-adjusted returns analysis

Methodology

Data Requirements

  • Historical Period: 5 years of daily OHLCV data
  • Data Source: yfinance API
  • Symbols: 21 global market indices
  • Frequency: Daily bars

Execution Logic

  1. Calculate technical indicators for each symbol
  2. Generate trading signals based on strategy rules
  3. Simulate order execution with realistic assumptions
  4. Track portfolio value and positions over time
  5. Calculate performance metrics and risk statistics

Trading Assumptions

Costs & Slippage

  • • Commission: $0 (zero-commission brokers)
  • • Slippage: 0.1% per trade
  • • Spread: Included in slippage

Position Sizing

  • • Initial Capital: $100,000
  • • Position Size: 100% of capital
  • • No leverage

Order Execution

  • • Entry: Next day's open price
  • • Exit: Next day's open price
  • • Market orders only

Risk Management

  • • Stop-loss: Strategy-dependent
  • • Take-profit: Strategy-dependent
  • • Max position: 100%

Performance Metrics

All strategies are evaluated using the following metrics:

Sharpe Ratio

Risk-adjusted return measure. Higher is better. Formula: (Return - Risk-free rate) / Volatility

Total Return

Cumulative percentage return over the backtest period.

Maximum Drawdown

Largest peak-to-trough decline in portfolio value. Lower is better.

Win Rate

Percentage of profitable trades. Higher is better.

Calmar Ratio

Return divided by maximum drawdown. Higher is better.

Sortino Ratio

Similar to Sharpe but only considers downside volatility.

Implementation

Technology Stack

Execution Flow

1. Load historical data from yfinance
2. Calculate technical indicators
3. Generate trading signals
4. Simulate order execution
5. Track portfolio performance
6. Calculate metrics
7. Export results to JSON
        

Limitations & Considerations