A simple, practical Python framework for backtesting intraday trading strategies on real or synthetic data. It includes a small set of strategies, a realistic backtester (bid/ask, latency, fees), and basic analytics.
- Data: Yahoo Finance intraday download (no API key), CSV input, or synthetic data
- Strategies: Mean reversion, momentum, market making (extensible via
BaseStrategy) - Backtester: Bid/ask matching, latency, slippage, transaction fees, average-cost P&L
- Metrics & Plots: Sharpe, drawdown, win rate, equity curve and drawdown charts
- CLI: Single entry point with sensible defaults
git clone <your-repo-url>
cd TradingBot
pip install -r requirements.txt# Run with real market data from Yahoo Finance (e.g., AAPL)
python main.py --symbol AAPL
# Choose a different strategy and parameters
python main.py --symbol TSLA --strategy momentum --lookback 30 --threshold 0.002
# Market making with position limits
python main.py --symbol SPY --strategy market_making --max-position 200# Show all CLI options
python main.py -h
# Advanced configuration example
python main.py \
--symbol NVDA \
--strategy mean_reversion \
--lookback 120 \
--threshold 0.8 \
--latency-ms 100 \
--fee-per-share 0.001 \
--slippage-bps 5 \
--period 5dmain.py— CLI entry pointdata_loader.py— Yahoo Finance download, CSV I/O, synthetic databacktester.py— Core execution (bid/ask, latency, fees, slippage, P&L)strategies/—base.py,mean_reversion.py,momentum.py,market_making.pymetrics.py— Sharpe, drawdown, win rate, etc.plotting.py— Equity, drawdown, exposure, P&L distributiontests/— Basic pytest for a synthetic run
- Add a strategy by subclassing
strategies/base.pyand implementingon_tick() - Add a data source under
data_sources/implementing the base interface
pytest -qThis project is for educational and research purposes only. It is not investment advice and not intended for live trading.