I’m building a backtesting engine for Indian markets where backtest, paper, and live all use the same logic. Option buying is straightforward since capital required is just the premium, but option selling is much more complex due to margin requirements. The margin isn’t fixed because it depends on SPAN and exposure and keeps changing with market conditions. It also varies based on the overall portfolio, especially when using hedged strategies like spreads, where margin gets reduced. On top of that, intraday and overnight margins are different, which adds another layer of complexity.
What I want is to simulate realistic capital usage in backtesting, including support for both naked option selling and hedged positions, while keeping behavior close to live trading. My main question is what the practical approach should be here — do people actually try to replicate full SPAN margin in backtests, or is it better to use some approximation? Also, how do you handle margin benefits from hedged positions in a simplified model? And finally, if margin is simplified too much, does it make the backtest results unreliable?
Most retail and independent algo traders don’t bother replicating a full real-time SPAN. And honestly, that makes sense. Doing so is computationally brutal. Instead, they either use approximations or lean on end-of-day SPAN files.
The Approximate Approach would help if your goal is to get backtesting off the ground without drowning in margin mechanics; a fixed approximation is a fine starting point.
For naked shorts, hardcode a conservative estimate of ₹2–2.5 lakh per lot for Nifty or BankNifty. For hedged positions like spreads, cap the margin at max loss (strike difference × lot size) and throw in a fixed buffer for exposure. That’s it. The tradeoff is that your Return on Capital figures won’t hold up well during high-IV periods, when exchange margins tend to spike, and your estimates quietly drift from reality.
The Semi-Accurate Approach would be SPAN + Exposure Logic. You pull the daily SPAN files directly from NSE, which gives you the base margin for naked options on any given date. Exposure margin gets calculated separately; it’s a straightforward percentage of contract value, derived from the underlying’s LTP in the daily Bhavcopy. In the backtest, your system looks up the historical SPAN file for the exact date, adds the dynamically computed exposure on top of it, and blocks that capital accordingly.