A lightweight, modular backtesting engine for evaluating trading strategies on historical stock data.
Perfect for learning quantitative finance, comparing strategies, and building your own framework.
- CLI interface with interactive menu
- Fetches historical stock data via Yahoo Finance
- Modular strategy architecture (easy to add your own)
- Computes performance metrics:
- CAGR
- Sharpe Ratio
- Max Drawdown
- Grid Search for:
- Moving Average Crossover
- RSI Strategy
- Saves results in CSV and visualizes equity curves
git clone https://github.com/tibonigabriele/quant-backtester-python.git
cd quant-backtester-python
pip install -r requirements.txt
python main.pyMake sure you're connected to the internet: the script fetches data using
yfinance.
What would you like to do?
1. Run base strategies (Buy & Hold, MA, RSI)
2. Launch MA Crossover grid search
3. Launch RSI grid search
4. Exit
- Buy & Hold β benchmark strategy
- Moving Average Crossover β customizable short/long windows
- RSI Strategy β buy when RSI < 30, sell when RSI > 70
| Strategy | CAGR | Sharpe Ratio | Max Drawdown |
|---|---|---|---|
| MA 10-200 | 0.1122 | 0.95 | 0.1377 |
| MA 10-100 | 0.1018 | 0.90 | 0.1966 |
| Strategy | CAGR | Sharpe Ratio | Max Drawdown |
|---|---|---|---|
| RSI 10-20-80 | 0.0954 | 0.87 | 0.1456 |
| RSI 14-30-70 | 0.0889 | 0.81 | 0.1823 |
Both outputs are automatically ranked using a weighted performance score.
quant-backtester-python/
βββ main.py # Entry point with CLI menu
βββ requirements.txt # Python dependencies
βββ LICENSE # MIT License
βββ README.md # This file
βββ results/ # CSV files from grid search
βββ plots/ # Saved equity curve images
βββ src/
β βββ data_loader.py
β βββ performance_metrics.py
β βββ plotter.py
β βββ print_metrics.py
β βββ strategies/
β βββ buy_hold_strategy.py
β βββ ma_crossover_strategy.py
β βββ rsi_strategy.py
βββ analysis/
βββ grid_search.py # tuning logic
Project by Gabriele Tiboni
Feel free to reach out for feedback or collaboration!
