There are no items in your cart
Add More
Add More
Item Details | Price |
---|
A data-driven exploration of momentum vs mean reversion in Indian equity markets using 1,781 stocks and AI-powered analysis
Thu Jul 10, 2025
Every trader has wondered this at some point: When a stock surges 10% today, will it continue rallying tomorrow? Or is it due for a pullback? Similarly, when a stock crashes, does it bounce back the next day or continue its downward spiral? This age-old debate between momentum (trends continue) and mean reversion (extremes reverse) has fascinated traders for decades. Instead of relying on gut feelings or anecdotal evidence, I decided to test this systematically using data from the Indian stock market.
To test this, I needed to:
Step 1: Getting Historical Data As I don't know coding, I gave the @DhanHQ api documentation link https://pypi.org/project/dhanhq/ to Claude Ai, asked it to keep it for reference to download Daily historical data and also asked it to refer api-scrip-master.csv file to grab all secruity id for equity cash segment only and download the daily historical data for them. Instantly it gave the code.
Step 2: We need Client id and access token to autheticate the account, only then you can download the data. You can generate api token from your dhan account and pass on your client id information to the code given by Claude.
With Claude AI's assistance, I built a robust downloader that:
Step 3: Calculating Daily Returns (ROC) Raw price data isn't enough - I needed to calculate daily returns for each stock. The Rate of Change (ROC) formula is straightforward:
But applying this across 1,781 files with hundreds of rows each required automation. Again, Claude AI helped create an efficient processor that:ROC = ((Today's Close - Yesterday's Close) / Yesterday's Close) × 100
Step 4: Building the Backtesting Engine This is where things got interesting. The backtesting engine needed to:
The biggest insight came when I noticed many top gainers were illiquid stocks with low trading volumes. A 20% gain means nothing if you can't actually trade the stock! So introduced a composite ranking system.
# Rank by trading value (liquidity)stock['value_rank'] = stock['Value'].rank(ascending=False)# Rank by ROC (momentum)stock['roc_rank'] = stock['ROC'].rank(ascending=False)# Composite score (lower is better)stock['composite_score'] = value_rank × roc_rank
Key Insights from the Analysis After processing 20,000+ trades across 128 trading days, several patterns emerged:
1. Liquidity is Crucial High-volume stocks showed more reliable patterns than low-volume ones. The composite ranking system significantly improved strategy stability.
2. Extreme Moves Often Reverse Stocks with daily moves exceeding ±7% showed higher tendency to reverse the next day, supporting mean reversion.
3. Moderate Momentum Persists Stocks with 2-5% gains showed slight positive momentum the next day, while those with 2-5% losses continued declining.
4. The Power of Long/Short Combining long and short positions reduced overall volatility while maintaining returns. The correlation between long and short P&L was negative, providing natural hedging.
5. Day-of-Week Effects Mondays showed different patterns than other days, possibly due to weekend news absorption and global market movements.
Don't trade based on hunches. With modern tools, backtesting strategies is easier than ever. A 20% gain in an illiquid stock is meaningless if you can't exit your position. Single-factor strategies (just ROC) are inferior to multi-factor approaches (ROC + Volume). Long-only strategies are more volatile than long/short combinations. Remember to factor in brokerage, STT, and slippage in real trading.
Earlier I use to spend hours/days with vlookup , hlookup in excel to perform similar analysis. Now the same can be done in seconds with the help of ai! Anyone can test trading ideas with the right tools! Whether you believe in momentum or mean reversion, TEST IT! Don't trade on hunches. Let data guide your decisions. With modern APIs and AI coding tools, there's no excuse for not validating your trading ideas.
Kirubakaran Rajendran
Full Time Algo Trader