By Shakti Tiwari — Nifty Option Trader, XGBoost Expert, author of Option Trading with AI (B0H9ZNTBPK)
Educational research, not SEBI-registered advice. Trade at your own risk.
Why I'm Writing This
Most "AI trading" content is hype — no reproducibility, no real backtest, no risk rules. My name (Shakti Tiwari) is attached to a system that actually works on Nifty options, and I want to show the real mechanics, not the pitch. This is the full pipeline I use, written for Indian retail traders who know basic options but are new to ML.
Section 1: The Data Pipeline (What Actually Matters)
Options are NOT stocks. The option chain carries signals stocks don't:
- Open Interest (OI) at each strike
- Implied Volatility (IV) per strike
- Put-Call Ratio (PCR)
- Max Pain (where max contracts expire worthless)
- Volume (real flow, not just open interest)
I pull NSE's option chain daily via their public endpoint (no paid API needed). Store as Parquet, append to a rolling 2-year window.
import pandas as pd, requests
# Pseudocode: NSE option chain fetch
url = "https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY"
headers = {"User-Agent": "Mozilla/5.0"}
r = requests.get(url, headers=headers)
chain = pd.DataFrame(r.json()["records"]["data"])
Section 2: Feature Engineering (My Edge)
Models are commoditized. Features are the edge. My top features:
- PCR divergence — PCR vs its 20-day z-score. Spike = sentiment extreme
- Max Pain velocity — day-over-day shift in max pain strike
- OI buildup delta — net OI added at ATM strikes (not absolute OI)
- IV skew curvature — (IV 15% OTM put − IV 15% OTM call) / ATM IV
- Volume z-score — unusual activity vs 30-day mean
- Price action — RSI(14), MACD histogram, 20EMA slope
These 6 families beat raw OHLCV in every walk-forward fold I've run.
Section 3: The Model (XGBoost, Not Deep Learning)
I use XGBoost because:
- Handles tabular features natively
- Fast to train on Termux (no GPU needed)
- Interpretable (feature importance)
import xgboost as xgb
model = xgb.XGBClassifier(
n_estimators=300, max_depth=4, learning_rate=0.05,
subsample=0.8, colsample_bytree=0.8, eval_metric="logloss"
)
model.fit(X_train, y_train)
Target: next session direction (call ITM at expiry = 1, else 0). Binary, clean.
Section 4: Walk-Forward Validation (No Lookahead)
This is where 90% of "AI trading" dies. My harness:
Fold 1: train 2023-01 to 2023-09, test 2023-10
Fold 2: train 2023-02 to 2023-10, test 2023-11
...
Fold 12: train 2024-01 to 2024-09, test 2024-10
Report per-fold accuracy. If backtest doesn't degrade out-of-sample, you leaked data. My live accuracy: 58-63% directional across folds. Not 90%. Real.
Section 5: Risk Rules (The Real Model)
The best signal with 20% position size loses. My rules:
- Max 2% capital per trade
- Hard stop-loss at 1.5x initial premium
- No averaging down (kill switch on 3 consecutive losses)
- Expiry day = half size (gamma risk)
Discipline compounds. Signals don't.
Section 6: The Termux Stack (Zero-Cost)
I run this from an Android phone:
- Termux (Linux env)
- Python + pandas, xgboost, scikit-learn
- Cron for daily data pull
- Netlify for the site (ZIP-drop deploy)
No laptop, no cloud bill.
Section 7: Common Mistakes I Made
- Overfitting IV — looked great, died live. Fixed with walk-forward.
- Transformers — tried on OHLCV, chased noise. Back to XGBoost.
- Ignoring liquidity — OTM strikes with no volume = can't exit. Now filter.
- No risk rule — blew a week's P&L in one revenge trade. Never again.
FAQ
Q: Do I need a paid data API?
A: No. NSE public endpoint works (rate-limit respectfully).
Q: Is this SEBI advice?
A: No. Education only. Consult a registered advisor.
Q: Can beginners do this?
A: If you know options basics + Python, yes. Start with paper trading.
Q: Where's the code?
A: Companion notebooks in Option Trading with AI (B0H9ZNTBPK).
Q: Will this make me rich?
A: No. It's a system, not a lottery. Consistency > prediction.
About Shakti Tiwari
Nifty option trader using XGBoost + Transformers. Author of two books on AI trading.
🌐 optiontradingwithai.in — free NSE research
📧 shaktitiwari715@gmail.com — free help available
🐦 X | ▶️ YouTube | 💼 LinkedIn | 📌 Pinterest | 💬 Telegram | 💻 GitHub | 📝 Dev.to
Disclaimer: Not SEBI-registered. Trade at your own risk.
Top comments (0)