A quantitative investment strategy that invests ₹1,00,000 whenever the monthly RSI drops below 45, aiming to capture undervaluation opportunities.
Backtested with historical data, calculated key metrics (CAGR, Drawdown, Sharpe, Hit Ratio), visualized portfolio growth, and compared RSI-timed SIP vs fixed SIP to highlight benefits and risks.
This project implements and backtests a Systematic Investment Plan (SIP) strategy that invests a fixed amount (default: ₹1,00,000) whenever the monthly Relative Strength Index (RSI) falls below a chosen threshold (default: 45).
The objective:
Does buying during weaker market momentum lead to better long-term results than a fixed monthly SIP?
- Load historical price data from a CSV.
- Resample to monthly and compute RSI (default period: 14).
- If RSI < threshold → invest ₹1,00,000 (fractional units allowed).
- Track units purchased and portfolio value.
- Compute performance metrics and visualize growth.
- Customizable Parameters
- Investment amount per trade
- RSI threshold
- RSI window length
- Performance Metrics
- CAGR (Compound Annual Growth Rate)
- Sharpe Ratio
- Maximum Drawdown (MDD)
- Annualized Volatility
- Hit Ratio (12-month forward returns)
- Average Return per Trade (12-month forward)
- Capital Utilization
- Visualization
- Portfolio value chart
- Buy markers
| Date | Price (INR) | Units Bought | Investment (INR) |
|---|---|---|---|
| 2001-03-01 | 1528.45 | 65.41 | 100000 |
| 2002-07-01 | 1402.22 | 71.29 | 100000 |
| 2004-09-01 | 1750.10 | 57.14 | 100000 |
| ... | ... | ... | ... |
For the full trade log, see trades.csv.
git clone https://github.com/yourusername/monthly-rsi-sip.git
cd monthly-rsi-sip
pip install pandas numpy matplotlib
Notes
Uses np.irr for CAGR — in newer NumPy versions this is deprecated; consider replacing with numpy_financial.irr or a date-aware XIRR method for better accuracy.
No reinvestment of dividends is assumed.
Works best with monthly price data; resample daily data before running
License
This project is licensed under the MIT License.
