Skip to content

🧠 A lightweight, modular Python engine to backtest trading strategies like Buy & Hold, MA Crossover, and RSI on historical data. Includes performance metrics and equity curve visualization.

License

Notifications You must be signed in to change notification settings

tibonigabriele/quant-backtester-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Quant Backtester

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.


πŸš€ Features

  • 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

πŸ“Έ Demo

Equity Curve


βš™οΈ How to Use

git clone https://github.com/tibonigabriele/quant-backtester-python.git
cd quant-backtester-python
pip install -r requirements.txt
python main.py

Make sure you're connected to the internet: the script fetches data using yfinance.


🧠 CLI Menu

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

πŸ’‘ Included Strategies

  • Buy & Hold – benchmark strategy
  • Moving Average Crossover – customizable short/long windows
  • RSI Strategy – buy when RSI < 30, sell when RSI > 70

πŸ“Š Sample Grid Search Output

πŸ“‰ MA Crossover Results (results/ma_crossover_results.csv)

Strategy CAGR Sharpe Ratio Max Drawdown
MA 10-200 0.1122 0.95 0.1377
MA 10-100 0.1018 0.90 0.1966

πŸ”„ RSI Strategy Results (results/rsi_grid_search_results.csv)

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.


πŸ“‚ Project Structure

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

πŸ“¬ Contact

Project by Gabriele Tiboni
Feel free to reach out for feedback or collaboration!

About

🧠 A lightweight, modular Python engine to backtest trading strategies like Buy & Hold, MA Crossover, and RSI on historical data. Includes performance metrics and equity curve visualization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages