Strategy Backtesting Bot is a trading strategy testing framework that allows you to backtest various trading strategies using historical market data. It supports multiple asset types, configurable parameters, and Telegram bot integration for interactive backtesting.
- Supports multiple strategies (SMA-RSI, MACD, Bollinger Bands, Stochastic, ATR Breakout)
- Multi-asset and single-asset trading
- Configurable portfolio settings (initial cash, fees, slippage, stop-loss, take-profit)
- Historical data fetching and storage in Parquet format
- Backtest result visualization and CSV export
- Telegram bot integration for remote testing and monitoring
- Clone the repository:
git clone https://github.com/velinamons/Strategy-back-testing.git cd Strategy-back-testing - Install the required dependencies:
pip install -r requirements.txt
- Create a
.envfile based on the.env.sampleprovided (get tg token using @BotFather):cp .env.sample .env
- Modify
config.jsonto specify symbols and timeframes to preload:{ "symbols": { "BTCUSDT": { "30m": {"start_date": "2024-01-01", "end_date": "2025-01-01"}, "1h": {"start_date": "2024-01-01", "end_date": "2025-01-01"} } }, ... }
- Start the backtesting system:
python main.py
- Wait for historical data to load.
- Interact with the Telegram bot to trigger backtests and retrieve results using commands and by following instructions:
- Description: Starts the bot and shows the main menu.
- Description: Lists available trading symbols.
- Description: Displays portfolio configuration.
- Description: Shows available backtesting strategies.
- Description: Starts a single asset backtest by selecting a symbol.
- Description: Starts a multi-asset backtest by selecting multiple symbols.
- Combines Simple Moving Average (SMA) and Relative Strength Index (RSI) for trade signals.
- Parameters:
short_window,long_window,rsi_window,rsi_buy,rsi_sell
- Uses Moving Average Convergence Divergence (MACD) crossovers to generate trade signals.
- Parameters:
short_window,long_window,signal_window
- Generates buy/sell signals based on price crossing Bollinger Bands.
- Parameters:
window,num_std
- Uses the Stochastic Oscillator to identify overbought and oversold conditions.
- Parameters:
k_window,d_window,stoch_buy,stoch_sell
- Identifies breakouts and trends using the Average True Range (ATR).
- Parameters:
atr_window,atr_multiplier
Modify config.json to:
- Define symbols and timeframes for data fetching.
- Adjust portfolio parameters (fees, slippage, stop-loss, take-profit).
- Enable or disable specific strategies.
Modify .env to:
- Set environment variables (log level, data storage paths, Telegram token, etc.).
Backtest results are stored in the backtest_results/ directory:
- CSV files: Detailed trade history and performance metrics.
- PNG files: Visual representations of backtest performance.