A Python calculator for margin requirements on NSE Futures & Options trades. Computes SPAN margin, exposure margin, and total margin for equity derivatives, index options, and currency futures per SEBI regulations.
Since SEBI's peak margin rules introduced in 2021 (and updated through 2026), Indian traders must maintain adequate margins intraday — not just at end of day. This tool calculates the margin required for any F&O position on NSE, helping traders plan their capital allocation before entering trades.
- SPAN Margin — calculates initial margin based on SEBI's SPAN methodology
- Exposure Margin — additional margin required by the exchange
- Option Premium Margin — margin for option writers
- Spread Benefit — margin reduction for hedged positions (straddles, strangles, spreads)
- Currency F&O — USDINR, EURINR, GBPINR margin calculations
- What-If Analysis — estimate margin changes for hypothetical positions
pip install -r requirements.txtfrom margin_calc import MarginCalculator
calc = MarginCalculator()
# Nifty Futures margin
margin = calc.futures_margin(
symbol="NIFTY",
lot_size=25,
price=22500,
expiry="2026-04-24"
)
print(f"Total Margin Required: ₹{margin['total']:,.0f}")Output:
Total Margin Required: ₹1,15,625
| Segment | Instruments |
|---|---|
| Index Futures | Nifty 50, Bank Nifty, Finnifty, Midcap Nifty |
| Index Options | Weekly and monthly expiry options on indices |
| Stock Futures | All F&O eligible stocks (~200) |
| Stock Options | Monthly options on F&O stocks |
| Currency | USDINR, EURINR, GBPINR, JPYINR |
The minimum required margin calculated using Standard Portfolio Analysis of Risk. It considers:
- Price scan range (typically 3-6 standard deviations)
- Volatility scan range
- Inter-month spread charges
- Short option minimum charge
An additional margin over SPAN, typically:
- Index F&O: 3% of notional value
- Stock F&O: 5% or 1.5× standard deviation (whichever is higher)
Since SEBI's 2021 rules, brokers take 4 random snapshots during the trading day. The highest margin requirement becomes the peak margin. Shortfall attracts penalties.
Calculate margins for multi-leg strategies with spread benefits:
# Bull Call Spread
strategy_margin = calc.strategy_margin([
{"type": "CE", "strike": 22500, "action": "BUY", "lots": 1},
{"type": "CE", "strike": 22700, "action": "SELL", "lots": 1},
], underlying="NIFTY", price=22500)
print(f"Strategy Margin: ₹{strategy_margin['total']:,.0f}")
print(f"Spread Benefit: ₹{strategy_margin['spread_benefit']:,.0f}")| Instrument | Lot Size | Approx. Margin | Margin % |
|---|---|---|---|
| Nifty Futures | 25 | ₹1,15,000 | ~20% |
| Bank Nifty Futures | 15 | ₹1,05,000 | ~15% |
| Reliance Futures | 250 | ₹3,20,000 | ~25% |
| Nifty 22500 CE (write) | 25 | ₹95,000 | varies |
| USDINR Futures | 1000 | ₹2,500 | ~3% |
- Margin Trading India Explained — comprehensive guide to how margins work for Indian F&O traders, including peak margin rules and penalty structures
- Nifty 50 Trading Strategies — strategies for trading Nifty futures and options with proper margin management
- Best Trading App India 2026 — brokers with the best margin policies and lowest margin requirements for Indian traders
See margin_calc.py for full API documentation with docstrings.
This calculator provides approximate margin estimates. Actual margin requirements depend on real-time volatility, your broker's risk management policies, and SEBI/exchange circulars. Always verify with your broker before placing trades.
Contributions welcome, especially for adding real-time SPAN file parsing.
MIT License — see LICENSE for details.