This project is a modular backtesting engine built with Python and Streamlit. It lets you test trading strategies on historical data with configurable execution models, slippage assumptions, and order types. The engine is designed to be flexible, extensible, and straightforward to demo.
-
Data Handling
- Historical equity prices via OpenBB (default provider:
yfinance). - Single- or multi-asset backtests.
- Historical equity prices via OpenBB (default provider:
-
Strategy Framework
- Define custom strategies by composing:
- Indicators (e.g., rolling highs/lows, SMAs).
- Signal logic (buy/sell/hold).
- Included example strategies:
- Volume Breakout
- SMA Crossover
- Define custom strategies by composing:
-
Execution & Slippage
- Market and Limit orders.
- Static slippage (fixed %) and Dynamic slippage (market-impact based on dollar volume).
-
Backtesting Engine
- Capital allocation, positions, commissions (percent and fixed), portfolio value tracking.
-
Performance Analytics
- Total Return, Annualized Return/Volatility, Sharpe, Sortino, Max Drawdown.
- Charts for portfolio value and daily returns.
-
Streamlit UI
- Inputs for ticker, strategy, order type, slippage model.
- One-click backtest and metric display.
Add these to requirements.txt:
- streamlit
- pandas
- numpy
- openbb
- yfinance
- matplotlib (optional; Streamlit charts are used)
Run the Streamlit app:
streamlit run main.py-
Enter a ticker (e.g., AAPL).
-
Choose a strategy (volume_breakout or sma_crossover).
-
Select order type (Market or Limit).
-
Pick slippage model (static, dynamic, or none).
-
Run the backtest.
-
Review metrics and charts.
src/
├── backtest/
│ └── backtester.py # Backtesting engine
├── data/
│ └── data_handler.py # Data loading (via OpenBB)
├── performance/
│ └── metrics.py # Performance metrics
├── strategy/
│ └── strategy.py # Strategy framework
main.py # Streamlit frontend entry point
requirements.txt # Dependencies
README.md # Documentation
.gitignore # Git ignore rules
-
Volume Breakout
Buy when close ≥ rolling 20-day high with above-average volume.
Sell when close ≤ rolling 20-day low with above-average volume.
-
SMA Crossover
Buy when 20-day SMA > 60-day SMA.
Sell when 20-day SMA < 60-day SMA.
MIT License