This project implements a straightforward backtesting framework for a simple moving average (SMA) crossover trading strategy using Python and Pandas.
Deployed with StreamLit- https://backtesting-ezi3yt44q5da2siz2eu4c6.streamlit.app/
It allows you to:
- Fetch and clean historical stock data
- Calculate fast and slow SMAs (e.g., 20-day and 50-day)
- Generate buy/sell signals based on SMA crossovers
- Simulate trading behavior with capital allocation
- Track portfolio value over time
- Visualize trades and portfolio performance
Buy Signal: When the short-term SMA crosses above the long-term SMA Sell Signal: When the short-term SMA crosses below the long-term SMA
The backtester assumes 100% capital is invested on each buy and fully liquidated on each sell (no position sizing logic yet).
-
Number of Buy and Sell signals
-
Final Portfolio Value
-
Line plot of: Closing prices, SMA lines, Buy/Sell signals, Portfolio value over time
-
pandas – data manipulation
-
numpy – numerical computations
-
matplotlib – visualization
-
yfinance – fetching historical stock data