Know the exact margin for any F&O trade — on your own computer, instantly.
Give it the exchange's daily SPAN file and your position(s); it returns the SPAN margin, Exposure margin, total margin, and the margin you save by hedging — the same numbers a broker's calculator shows. Offline, no login, pure Python.
pip install marginismfrom marginism import RiskEngine
eng = RiskEngine.from_file("nsccl.20260529.s.spn") # load once, reuse
result = eng.basket([
{"tradingsymbol": "NIFTY26JUN23700CE", "transaction_type": "SELL", "quantity": 65},
])
print(result["data"]["final"]["total"]) # 172285quantity is in units (lots × lot size; NIFTY 65 = 1 lot). transaction_type
is BUY/SELL. Pass one leg or many.
# Short straddle — sell 23700 CE + 23700 PE
eng.basket([
{"tradingsymbol": "NIFTY26JUN23700CE", "transaction_type": "SELL", "quantity": 65},
{"tradingsymbol": "NIFTY26JUN23700PE", "transaction_type": "SELL", "quantity": 65},
])
# TOTAL = 2,02,898 | margin benefit = 1,38,269
# Protective put — buy future + buy 23000 PE (hedge lowers margin)
eng.basket([
{"tradingsymbol": "NIFTY26JUNFUT", "transaction_type": "BUY", "quantity": 65},
{"tradingsymbol": "NIFTY26JUN23000PE", "transaction_type": "BUY", "quantity": 65},
])
# TOTAL = 78,904 | margin benefit = 95,689See example.py for 10 ready-made strategies (straddle, strangle,
covered call, calendar spread, iron condor, …).
{"symbol": "NIFTY", "instrument": "CE", "expiry": "2026-06-30", "strike": 23700,
"transaction_type": "SELL", "quantity": 65}Download the latest daily SPAN file from your exchange clearing house and point
the engine at it. For NSE F&O (nsccl.YYYYMMDD.s.spn) see NSE Clearing's
NSCCL SPAN page.
eng = RiskEngine.from_file("nsccl.20260529.s.spn") # same folder
eng = RiskEngine.from_file(r"C:\Users\you\Downloads\file.spn") # WindowsWorks for NFO, currency (CDS), and commodity (MCX) files.
Margin figures are estimates — always confirm with your broker before trading.
Not financial advice. MIT licensed. Full API details in
marginism/README.md.
The software is provided "as is", without warranty of any kind. The author accepts no responsibility or liability for any errors or inaccuracies in the calculations, or for any trading losses, damages, or decisions arising from its use. Margins depend on the SPAN file and exposure rates you supply, may differ from your broker's, and must be independently verified before trading. Use at your own risk.
This is an independent project built by an independent developer. It is not affiliated with, sponsored by, endorsed by, or connected to NSE, NSE Clearing (NSCCL), the Chicago Mercantile Exchange (CME), or any broker or exchange.
SPAN® is a registered trademark of Chicago Mercantile Exchange Inc. All other trademarks are the property of their respective owners. Any names are used only for identification/descriptive purposes (nominative use) and do not imply any affiliation, endorsement, or license.