Menu

I Built a Sector Rotation Map in Python. A Shuffle Test Humbled It.
📰

I Built a Sector Rotation Map in Python. A Shuffle Test Humbled It.

DEV Community: datascience·sanjay mehta·about 1 month ago
#kTWehMVp
#devtodatascience#science#devto#dev#nifty
Long article (2672 words) — no AI summary yet.
Reading 0:00
15s threshold

This week I shipped a sector rotation map for Indian stocks. It plots NSE sector and thematic indices against the Nifty 500 and sorts them into four corners: Leading, Weakening, Lagging and Improving.

Then the obvious question hit me: does it actually tell you anything? If you buy whatever is Leading, do you beat the market? And do sectors really travel clockwise around the map, the way every explainer says?

So I rebuilt the whole thing in Python, ran it over ten years of weekly data, and checked. This post is the build: the maths, the code, two bugs, and a shuffle test that took my favourite finding away. The story version, with more charts, is on Medium (linked at the end).

Not investment advice. I built the data platform and the map used here. Data runs from July 2016 to 23 October 2026.

The maths

Every week, for every sector:

rs = 100 * sector / nifty_500 # relative strength ratio = 100 * wma ( rs , 5 ) / wma ( rs , 15 ) # has it been gaining ground lately? mom = 100 * ratio / ratio .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.