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:
- Asymmetric position range [β0.5, 1.5] β couldn't go aggressively long vol
- No regime detection β relied only on spike probability, missed sustained bear trends
- VRP turns negative in bear markets β short vol bleeds when RV > IV consistently
- No drawdown protection β held full short vol position through crashes
v5 Fixes
- Bear Regime Detection Head β 4th auxiliary task predicting forward 22-day bear regime
- 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
- Multi-Confirmation Long Vol β requires bear_prob > 0.8 AND spike > 0.6 AND drawdown < β10% AND VRP < 0 (prevents false signals)
- Gradual Position Reduction β scales down smoothly in bear regime instead of binary switching
- Deep Drawdown Circuit Breaker β flattens position at >15% drawdown with negative VRP
- 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 checkpointnifty_vol_trading_v5_bear.pyβ v5 complete training + backtest pipelinebacktest_results_v5.csvβ v5 backtest resultsbacktest_results_v5.pngβ v5 comprehensive visualizationrecent_performance_v5.pngβ v5 recent 6-month detailday_by_day_backtest_v5.pngβ v5 vs always-short comparisonmetrics_v5.jsonβ v5 metrics (includes Bear Sharpe)
v3 (Original Bull-Biased)
nifty_vol_model_final.ptβ v3 trained modelnifty_vol_trading_v3.pyβ v3 training pipelinebacktest_results.csv/backtest_results.pngβ v3 resultsmetrics.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
- Corsi, F. (2009). "A Simple Approximate Long Memory Model of Realized Volatility." J. Financial Econometrics
- Lim et al. (2023). "Constructing Time-Series Momentum Portfolios with Deep Multi-Task Learning." arXiv:2306.13661
- Qin et al. (2024). "Dynamic Graph Neural Networks for Enhanced Volatility Prediction." arXiv:2410.16858
- MichaΕkΓ³w et al. (2025). "Forecasting Probability Distributions of Financial Returns with Deep Neural Networks." arXiv:2508.18921
- Hofmann et al. (2021). "A Two-Step Framework for Arbitrage-Free Prediction of the Implied Volatility Surface." arXiv:2106.07177
- Chen & Zhang (2019). "Forecasting Implied Volatility Smile Surface via Deep Learning and Attention Mechanism." arXiv:1912.11059
- Vallarino (2025). "Adaptive Market Intelligence: A Mixture of Experts Framework for Volatility-Sensitive Stock Forecasting." arXiv:2508.02686