π RSI Backtesting Strategy
A complete, customizable RSI-based trading strategy backtester built with Python. This tool downloads historical market data using yfinance, computes RSI, generates buy/sell signals, simulates an all-in/all-out trading strategy, compares performance against buy & hold, and displays clean, high-quality visualizations.
π Features β Data Handling
Fetches OHLC data using yfinance
Automatically processes timestamps
Handles missing data gracefully
β Technical Indicator
Computes Relative Strength Index (RSI)
Configurable RSI period, buy threshold, sell threshold
Clean, vectorized Pandas implementation
β Signal Generation
Buy when RSI crosses below the oversold threshold
Sell when RSI crosses above the overbought threshold
Tracks position (long/flat)
β Backtesting Engine
Simple all-in/all-out position model
Records every trade (date, action, price, shares, value)
Computes:
Portfolio value over time
Buy & Hold benchmark comparison
β Performance Metrics
Includes commonly used quantitative measures:
Total Return
Benchmark Return
Excess Return
Annualized Volatility
Sharpe Ratio
Maximum Drawdown
Win Rate
Total Trades
Trading Days
β Visualization
Creates professional, publication-quality charts:
Price chart with buy/sell markers
RSI indicator panel with thresholds
Portfolio vs Benchmark equity curves
β Fully Interactive CLI
Choose tickers
Define custom date ranges
Adjust RSI parameters
Optional preset examples
π Installation pip install yfinance pandas numpy matplotlib
You will be prompted for:
Ticker (e.g., TSLA, NVDA, QQQ)
Start date
End date
Initial capital
RSI period / thresholds
π Example Output
After running the analysis, the script prints a full summary including:
Strategy Total Return: XX% Buy & Hold Return: XX% Excess Return: XX% Sharpe Ratio: X.XX Max Drawdown: -XX% Win Rate: XX%
And opens 3 plots:
Price + Buy/Sell signals
RSI
Portfolio vs Benchmark