What I learned building "StockMind" and the maths that powers it. You can use it
Hey everyone,
A few days ago, I shared a post about building StockMind—a cash swing trading engine I coded to escape the F&O trap.
Over more than 200 people of you registered to check it out, and the feedback was a massive reality check. Here is a crisp retrospective on what this project has taught me about math, code, and transaction friction. May be you can incorporate it in your investing journey.
- The "Complexity Trap" in Machine Learning
As an ML engineer, my instinct was to throw complex deep learning models (like LSTMs) at price data. It failed. Stock prices are highly non-stationary; deep models just memorize historical noise (overfit) and blow up live.
I threw out the neural networks and went back to four simpler mathematical rules that actually work (At least it worked for me till now):
- Relative Strength (RS) Sector Rotation: Ranks sector indices against the Nifty 50 in last 2 months . We block all buy signals in the bottom 30% weak sectors.
- Quality + Momentum Filter:
- Quality: Filter out high debt (Debt/Equity < 1.5) and target efficiency (ROE > 15%).
- Momentum: Only enter if the asset is in a macro uptrend (Price > 150-day SMA).
- Cointegration & Stationarity (For Mean-Reversion):
- Math: Regresses the change in price spread between two assets against lagged values (ADF test). If p-value<0.05, we reject the unit root (non-stationarity) and trade the mean-reversion using Z-scores.
- NLP / Event Risk Filtering:
- Usage: Parses sentiment on the 5 most recent corporate news headlines. If the score falls below -0.3 (signaling lawsuits, fines, or bad earnings), the signal is blocked to avoid sudden gap-downs.
2. The "Friction Shock" is Real
Backtests assume you buy and sell at the exact closing price for free.
- The Reality: The second you add a flat 0.25% cost per trade (brokerage, GST, STT, and slippage), high-frequency strategies die.
- The Lesson: Keep holding periods longer (30+ days) to survive transaction costs.
3. Why I Kept 3 Different Strategies
No single strategy wins in every market regime. We run three to balance the portfolio:
- Pure-Momentum: Captures big breakouts in strong trending bull markets.
- Quality-DipBuy: Buys strong balance-sheet stocks at temporary discounts during market corrections.
- Unified-PM-QV: Blends both to smooth out the overall drawdown curve.
4. The Automation Illusion (Zerodha API Chores)
We want to write a cron job and let it run forever. But because Zerodha doesn't support free headless logins, I still have to manually log in to Kite every morning to generate the session token. It's a 30-second reminder that "fully automated" systems usually have a manual starting key. I can automate it but the process would require me to share my credentials inside the script which I don't want.
5. Honesty is a Superpower
I was terrified of sharing this because the win rate is only ~46% and the CAGR isn't 200%. Also it's the first time I was sharing one of the project in public. But people are tired of get-rich-quick scams. The raw stats brought in 150+ folks who visited the website and immediately pointed out math loopholes (like survivorship bias) that are helping me optimise the engine.
Status Update:
- The dashboard is live on our new domain: https://www.thestockmind.com
- Next Up: Working to extend the universe till Nifty 100. Analysing its pros and cons. Creating a dedicated community around StockMind where I would be sharing insights and updates. Feel free to join it.
Would love to hear from other builders—what was the biggest gap between your backtest and live execution?