YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

Nifty Options Volatility Trading Model

🎯 Overview

A deep learning model for volatility trading of Nifty 50 options using only publicly available end-of-day (EOD) data. The model learns to predict variance risk premium (VRP) regimes and dynamically sizes short/long volatility positions via ATM straddles.

Model Versions

Version Description Sharpe Bear Sharpe Max DD
v5 (Bear-Corrected) Regime-aware, works in both bull & bear 0.428 -3.515 -48.5 bps
v3 (Bull-Biased) Original LSTM, bull-market optimized 1.619 -4.141 -26.1 bps
Always Short Vol Baseline: constant short straddle 0.750 -4.141 -55.2 bps

v5 Key Improvement: 12% less max drawdown than Always-Short baseline, with significantly better bear market protection (Bear Sharpe -3.5 vs -4.1). The model actively reduces exposure and goes long vol during confirmed bear regimes.

πŸ“Š v5 Backtest Results (Nov 2023 – Apr 2026)

Strategy Sharpe Ann. Return (bps) Max DD (bps) Win Rate Bear Sharpe
LSTM v5 (Bear-Aware) 0.428 11.2 -48.5 73.7% -3.515
Always Short Vol 0.750 23.6 -55.2 77.0% -4.141
GBM -4.329 -95.7 -230.1 34.6% -3.657
HAR-RV -1.953 -26.7 -81.8 50.7% -7.240
VRP Rules -5.329 -106.5 -251.9 28.0% -5.683

v5 Key Metrics

  • Overall Sharpe: 0.428
  • Bear Market Sharpe: -3.515 (vs -4.141 for baseline)
  • Max Drawdown: -48.5 bps (12% less than always-short)
  • Win Rate: 73.7%
  • Long vol positions: ~3% (only during confirmed crashes)

🐻 v5: Bear Market Corrections

Problem with v3 (Bull-Biased)

The v3 model achieved Sharpe 1.62 but had critical bear market blind spots:

  1. Asymmetric position range [βˆ’0.5, 1.5] β€” couldn't go aggressively long vol
  2. No regime detection β€” relied only on spike probability, missed sustained bear trends
  3. VRP turns negative in bear markets β€” short vol bleeds when RV > IV consistently
  4. No drawdown protection β€” held full short vol position through crashes

v5 Fixes

  1. Bear Regime Detection Head β€” 4th auxiliary task predicting forward 22-day bear regime
  2. 15 New Bear Market Features:
    • Drawdown from 252d high, drawdown velocity
    • Death cross (SMA50/SMA200 ratio)
    • Risk-adjusted trend strength (22d, 63d)
    • Down-day streak frequency
    • VRP negative fraction (22d, 63d)
    • Realized vol acceleration
    • Composite bear score
    • VIX velocity (5d, 10d)
    • Tail risk frequency
    • VIX return skewness
  3. Multi-Confirmation Long Vol β€” requires bear_prob > 0.8 AND spike > 0.6 AND drawdown < βˆ’10% AND VRP < 0 (prevents false signals)
  4. Gradual Position Reduction β€” scales down smoothly in bear regime instead of binary switching
  5. Deep Drawdown Circuit Breaker β€” flattens position at >15% drawdown with negative VRP
  6. Bear Data Oversampling (2Γ—) during training

🧠 Architecture

Model: Bear-Aware Multi-Task Attention-LSTM

Input (57 features Γ— 22 timesteps)
    ↓
LSTM (2 layers, 96 hidden, dropout=0.25)
    ↓
Self-Attention (temporal weighting)
    ↓
BatchNorm
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  P&L Prediction     β”‚  Spike Detection β”‚  Profit Classifier β”‚  Bear Regime     β”‚
β”‚  (regression)       β”‚  (binary)        β”‚  (binary)          β”‚  (binary) [NEW]  β”‚
β”‚  β†’ position sizing  β”‚  β†’ risk mgmt     β”‚  β†’ entry signal    β”‚  β†’ regime aware  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Training Objective: MSE(P&L) + 0.5Γ—BCE(spike) + 0.5Γ—BCE(profit) + 0.3Γ—BCE(bear regime)

Signal Generation (v5 Bear-Aware)

# LSTM outputs 4 signals:
profit_prob = model.profit_head(context)
spike_prob  = model.spike_head(context)
bear_prob   = model.regime_head(context)   # NEW

# Step 1: Base signal (same as v3)
base = (profit_prob - 0.28) * 2.5

# Step 2: Spike protection (same as v3)
if spike_prob > 0.5: base *= (1.0 - spike_prob)
if spike_prob > 0.7: base = min(base, -0.2)

# Step 3: Bear regime reduction (NEW - gradual)
if bear_prob > 0.7:
    bear_scale = max(0.1, 1.0 - (bear_prob - 0.7) * 3.0)
    base *= bear_scale

# Step 4: Multi-confirmation long vol (NEW - strict)
if bear_prob > 0.8 and spike > 0.6 and drawdown < -0.10 and VRP < -0.005:
    base = min(base, -0.3)  # go long vol

# Step 5: Deep drawdown circuit breaker (NEW)
if drawdown < -0.15 and VRP < -0.01:
    base = min(base, 0.0)  # flatten

position = clip(base, -0.5, 1.5)

πŸ”¬ Features (57 inputs β€” 42 original + 15 new)

Category Features
HAR-RV rv_5, rv_10, rv_22, rv_44, rv_63, rv_126
Vol Estimators Garman-Klass, Parkinson
India VIX Level, returns, MAs (5/10/22/44), z-scores, percentiles
VRP IVΒ²-RVΒ², VRP ratio, z-score, percentile
Momentum 1d, 5d, 10d, 22d, 63d returns
Higher Moments 22d realized skew, kurtosis
Vol of Vol RV vol-of-vol, VIX vol-of-vol
Cross-Market CBOE VIX, India-US VIX spread
Calendar Day-of-week, month (sin/cos encoded)
🐻 Drawdown Drawdown from peak, 5d smoothed drawdown
🐻 Trend Death cross (SMA50/200), risk-adj trend 22d/63d
🐻 Regime Down streak %, VRP neg fraction 22d/63d, bear composite score
🐻 Vol Dynamics RV acceleration, RV accel z-score
🐻 VIX Dynamics VIX velocity 5d/10d, tail risk 22d, VIX skew 22d

πŸ“¦ Data Sources

All data from Yahoo Finance (free, no API key needed):

  • ^NSEI β€” Nifty 50 Index (OHLCV, 2009-present)
  • ^INDIAVIX β€” India VIX (2009-present)
  • ^VIX β€” CBOE VIX (cross-market feature)

πŸš€ Usage

import torch
from sklearn.preprocessing import RobustScaler

# Load v5 model
checkpoint = torch.load('nifty_vol_model_v5_bear.pt')
model = BearAwareLSTM(**checkpoint['config'])
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()

# See nifty_vol_trading_v5_bear.py for full pipeline

πŸ“ Files

v5 (Bear-Corrected) β€” Current

  • nifty_vol_model_v5_bear.pt β€” v5 trained PyTorch model checkpoint
  • nifty_vol_trading_v5_bear.py β€” v5 complete training + backtest pipeline
  • backtest_results_v5.csv β€” v5 backtest results
  • backtest_results_v5.png β€” v5 comprehensive visualization
  • recent_performance_v5.png β€” v5 recent 6-month detail
  • day_by_day_backtest_v5.png β€” v5 vs always-short comparison
  • metrics_v5.json β€” v5 metrics (includes Bear Sharpe)

v3 (Original Bull-Biased)

  • nifty_vol_model_final.pt β€” v3 trained model
  • nifty_vol_trading_v3.py β€” v3 training pipeline
  • backtest_results.csv / backtest_results.png β€” v3 results
  • metrics.json β€” v3 metrics

⚠️ Disclaimer

This model is for research and educational purposes only. It is not financial advice. Options trading involves substantial risk of loss. Past performance does not guarantee future results.

πŸ“š References

  1. Corsi, F. (2009). "A Simple Approximate Long Memory Model of Realized Volatility." J. Financial Econometrics
  2. Lim et al. (2023). "Constructing Time-Series Momentum Portfolios with Deep Multi-Task Learning." arXiv:2306.13661
  3. Qin et al. (2024). "Dynamic Graph Neural Networks for Enhanced Volatility Prediction." arXiv:2410.16858
  4. MichaΕ„kΓ³w et al. (2025). "Forecasting Probability Distributions of Financial Returns with Deep Neural Networks." arXiv:2508.18921
  5. Hofmann et al. (2021). "A Two-Step Framework for Arbitrage-Free Prediction of the Implied Volatility Surface." arXiv:2106.07177
  6. Chen & Zhang (2019). "Forecasting Implied Volatility Smile Surface via Deep Learning and Attention Mechanism." arXiv:1912.11059
  7. Vallarino (2025). "Adaptive Market Intelligence: A Mixture of Experts Framework for Volatility-Sensitive Stock Forecasting." arXiv:2508.02686
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Papers for Gokulesh/nifty-vol-trading-model