Skip to content

marcos99b/margin-calculator-india

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Margin Calculator for Indian F&O

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.

Overview

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.

Features

  • 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

Installation

pip install -r requirements.txt

Quick Start

from 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

Supported Instruments

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

Margin Types Explained

SPAN Margin (Initial Margin)

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

Exposure Margin

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)

Peak Margin

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.

Option Strategy Margins

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}")

Margin Table (Approximate as of March 2026)

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%

Recommended Resources

API Reference

See margin_calc.py for full API documentation with docstrings.

Disclaimer

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.

Contributing

Contributions welcome, especially for adding real-time SPAN file parsing.

License

MIT License — see LICENSE for details.

About

Margin requirement calculator for NSE futures and options — SPAN, exposure, and strategy margins

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages