Skip to content

DanielNg0729/RSI-Backtesting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ 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

▢️ Usage Run the full CLI program: python main.py

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:

RSI TRADING STRATEGY PERFORMANCE SUMMARY

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages