Python Trend-Following Stock Bot
Budget: ₹12,500 – ₹37,500 INR
Project: Titan-X Prime (Quantitative Options Scalper)
Target Environment: Python 3.13 (Free-Threaded/No-GIL)
Primary Goal: To capture high-conviction "Gamma Bursts" in Nifty Options while neutralizing the 2026 0.15% STT tax drag through microstructure-based precision.
1. System Architecture (Concurrency Model)
The system must utilize a Multi-Threaded Producer-Consumer model to leverage Python 3.13’s true parallelism.
• Thread 1 (Ingestion): WebSocket feed for Nifty Spot, Futures, and ATM/Near-OTM Option Chain (±10 strikes).
• Thread 2 (Microstructure): Real-time calculation of Weighted Order Book Imbalance (WOBI) every 100ms.
• Thread 3 (GEX Engine): Recalculation of Dealer Gamma Exposure (GEX) and Zero-Gamma Level every 60 seconds.
• Thread 4 (Execution): Signal validation (Quad-Gate) and Order Management (API calls).
2. The Quad-Gate Signal Logic
No order shall be fired unless all four gates return TRUE.
Gate 1: Physics (Regime Detection)
• Calculation: Total Net Gamma per strike ($OI \times \text{Gamma} \times \text{Spot}$).
• Logic: * Short Gamma Regime (Spot < Zero-Gamma): Trend-following/Breakout strategies ENABLED.
o Long Gamma Regime (Spot > Zero-Gamma): Mean-reversion only. Breakout signals DISABLED (to avoid chop).
Gate 2: Truth (Microstructure)
• Calculation: $WOBI = \frac{\sum (BidVol_i \times w_i) - \sum (AskVol_i \times w_i)}{\sum (BidVol_i \times w_i) + \sum (AskVol_i \times w_i)}$ where $w = [1.0, 0.5, 0.25, 0.125, 0.0625]$.
• Validation: * Long: $WOBI > 0.35$.
o Short: $WOBI < -0.35$.
Gate 3: Probability (ML Layer)
• Model: Lightweight XGBoost (pre-trained).
• Inputs: RSI Slope, Distance from VWAP, WOBI, Time of Day.
• Threshold: Probability score $> 0.65$.
Gate 4: Technical (The Trigger)
• Timeframe: 1-Minute Candle.
• Long Trigger: Close above Upper Bollinger Band (20, 2) + Candle Body $> 60\%$ of total range.
________________________________________
3. Execution & Risk Specs
• Instrument: Deep ITM Options ($\Delta \approx 0.70$) to maximize point capture vs. fixed STT.
• Entry: Limit Order at $LTP + 3$ points (Aggressive Fill).
• Sizing: Dynamic ATR-based sizing (Risk $\div$ (ATR $\times$ Lot Size)).
• Mandatory Stop Loss: Max(10% Premium, 8 points).
• Exit Protocol: 1. Fast Exit: Exit if $LTP < \text{Prev 1-min Low}$.
2. Predictive Exit: Exit if $WOBI$ flips sign for $> 3$ seconds.
3. Trail: Trigger 0.5x ATR trail once profit exceeds 1.5x ATR.
4. Technical Implementation Notes for Developer
1. Parallelism: Use threading.Thread with shared-memory objects; avoid multiprocessing to eliminate serialization latency.
2. Speed: Implement WOBI and GEX calculations using NumPy vectorization or Numba (JIT).
3. Connectivity: Use DhanHQ or Fyers API with a persistent WebSocket connection.
4. Tax Sensitivity: All "Break-Even" logic must be calculated as: $\text{Entry Price} + (\text{Total Statutory Charges} \div \text{Lot Size})$.
Target Environment: Python 3.13 (Free-Threaded/No-GIL)
Primary Goal: To capture high-conviction "Gamma Bursts" in Nifty Options while neutralizing the 2026 0.15% STT tax drag through microstructure-based precision.
1. System Architecture (Concurrency Model)
The system must utilize a Multi-Threaded Producer-Consumer model to leverage Python 3.13’s true parallelism.
• Thread 1 (Ingestion): WebSocket feed for Nifty Spot, Futures, and ATM/Near-OTM Option Chain (±10 strikes).
• Thread 2 (Microstructure): Real-time calculation of Weighted Order Book Imbalance (WOBI) every 100ms.
• Thread 3 (GEX Engine): Recalculation of Dealer Gamma Exposure (GEX) and Zero-Gamma Level every 60 seconds.
• Thread 4 (Execution): Signal validation (Quad-Gate) and Order Management (API calls).
2. The Quad-Gate Signal Logic
No order shall be fired unless all four gates return TRUE.
Gate 1: Physics (Regime Detection)
• Calculation: Total Net Gamma per strike ($OI \times \text{Gamma} \times \text{Spot}$).
• Logic: * Short Gamma Regime (Spot < Zero-Gamma): Trend-following/Breakout strategies ENABLED.
o Long Gamma Regime (Spot > Zero-Gamma): Mean-reversion only. Breakout signals DISABLED (to avoid chop).
Gate 2: Truth (Microstructure)
• Calculation: $WOBI = \frac{\sum (BidVol_i \times w_i) - \sum (AskVol_i \times w_i)}{\sum (BidVol_i \times w_i) + \sum (AskVol_i \times w_i)}$ where $w = [1.0, 0.5, 0.25, 0.125, 0.0625]$.
• Validation: * Long: $WOBI > 0.35$.
o Short: $WOBI < -0.35$.
Gate 3: Probability (ML Layer)
• Model: Lightweight XGBoost (pre-trained).
• Inputs: RSI Slope, Distance from VWAP, WOBI, Time of Day.
• Threshold: Probability score $> 0.65$.
Gate 4: Technical (The Trigger)
• Timeframe: 1-Minute Candle.
• Long Trigger: Close above Upper Bollinger Band (20, 2) + Candle Body $> 60\%$ of total range.
________________________________________
3. Execution & Risk Specs
• Instrument: Deep ITM Options ($\Delta \approx 0.70$) to maximize point capture vs. fixed STT.
• Entry: Limit Order at $LTP + 3$ points (Aggressive Fill).
• Sizing: Dynamic ATR-based sizing (Risk $\div$ (ATR $\times$ Lot Size)).
• Mandatory Stop Loss: Max(10% Premium, 8 points).
• Exit Protocol: 1. Fast Exit: Exit if $LTP < \text{Prev 1-min Low}$.
2. Predictive Exit: Exit if $WOBI$ flips sign for $> 3$ seconds.
3. Trail: Trigger 0.5x ATR trail once profit exceeds 1.5x ATR.
4. Technical Implementation Notes for Developer
1. Parallelism: Use threading.Thread with shared-memory objects; avoid multiprocessing to eliminate serialization latency.
2. Speed: Implement WOBI and GEX calculations using NumPy vectorization or Numba (JIT).
3. Connectivity: Use DhanHQ or Fyers API with a persistent WebSocket connection.
4. Tax Sensitivity: All "Break-Even" logic must be calculated as: $\text{Entry Price} + (\text{Total Statutory Charges} \div \text{Lot Size})$.