How to Build a Cash-Futures Arbitrage Scanner for NSE (2026)
How to build a cash futures arbitrage scanner for NSE: depth-based basis on executable prices, slippage and cost models, and the honest result after costs.

A cash-futures arbitrage scanner for NSE compares, for every stock with a futures contract, the price at which you could actually buy the stock against the price at which you could actually sell its future, subtracts every cost of carrying the pair to expiry, and ranks what is left as an annualised return. The two words doing all the work in that sentence are "actually" and "every". A scanner built on last-traded prices and a flat brokerage assumption will show you opportunities all day long; a scanner built on executable depth prices with slippage, STT, exchange charges, stamp duty and financing modelled will show you far fewer, and those are the only ones that matter.
I built one for a seven-figure rupee book whose owner wanted a low-risk 1.5 to 2 percent a month, and I will describe the engineering in detail. I will also tell you what the research found, because the honest answer to "what does the scanner show" was: after costs, nothing beat treasury bills. That result is as useful as a positive one if you were about to deploy capital. One sentence of framing: this is engineering, not investment advice, and the scanner never places orders.
What is cash-and-carry arbitrage on NSE?
Buy the stock in the cash market, sell the same quantity in the futures contract, hold both to expiry. At expiry the future settles to the cash price, the two positions cancel, and you keep the difference between the futures sale price and the cash purchase price, called the basis. Because the outcome is locked at entry, the basis is effectively an interest rate you earned on the cash you tied up. If that rate beats what the same cash earns risk-free, after all costs, the trade is worth doing.
The reverse trade (sell stock, buy future) needs you to own or borrow the stock, which is why retail arbitrage in India is almost entirely the long-cash, short-futures direction.
Why must the scanner use market depth instead of last price?
Because you cannot trade at the last price. You buy at the ask and sell at the bid, and for any meaningful quantity you walk several levels into the book. Using last-traded prices on both legs overstates the basis by the full bid-ask spread of both instruments, which on a mid-cap future is frequently larger than the entire arbitrage edge.
A correct scanner therefore:
- Pulls five levels of depth per side for both the stock and its near-month future.
- Computes the volume-weighted average price of buying the target quantity through the cash ask levels, and of selling it through the futures bid levels.
- Defines the gross basis as that futures sale VWAP minus that cash purchase VWAP, never as last minus last.
- Flags any pair where the available depth cannot absorb the target quantity at all.
That one change removes most of the "opportunities" a naive scanner shows. The remaining candidates are real in the sense that the book could fill them at that instant.
What costs decide whether the basis is worth it?
For a stock bought and held to expiry with a future sold against it, the full cost stack is:
- Brokerage on four executions (buy cash, sell future, and the unwind or settlement on both).
- Securities transaction tax, which is heavier on the delivery leg than on futures.
- Exchange transaction charges, SEBI fees, GST and stamp duty, each small, together not.
- Financing: the cash tied up in the stock for the holding period, at your real cost of funds or the T-bill rate you gave up.
- Margin opportunity cost on the futures leg.
- Slippage, already captured by the depth VWAP, plus a buffer for the book moving between quote and fill.
Subtract all of that from the gross basis, annualise over the days to expiry, and compare to the risk-free rate. Only the excess over risk-free is the edge. On most days, for most liquid names, that excess is near zero, which is exactly what you would expect in a market where large arbitrage desks already do this at lower costs than you.
Which traps make an arbitrage scanner lie?
The scanner itself was careful; the historical research around it was where the traps lived, and finding them changed the conclusion:
- Corporate actions. A dividend between entry and expiry lowers the stock price without touching your futures obligation symmetrically. If the data source adjusts futures contracts for dividends and you book that adjustment as profit, your backtest invents money. That bug existed in my first pass and was fixed.
- Stale expiry dates. A hard-coded or outdated expiry calendar silently dropped one month from the backtest. It happened to be the worst month. Fixing it moved the result materially downward.
- Instrument-master junk. The exchange instrument file contains test contracts and symbols that never trade. They show infinite basis and must be filtered.
- Zero-bid quotes after close. After the session, depth collapses and a zero bid on one leg reads as a huge gap. The scanner has to treat zero and crossed quotes as "no market", not as opportunity.
- Unverified corporate actions. Any candidate with a pending but unconfirmed event is flagged, because its basis is probably explained by that event rather than by inefficiency.
If you are new to broker APIs in India and wondering which one to build on, I compared the options in best broker for TradingView automation in India; the same data considerations apply to a read-only scanner.
Can you find any edge after costs?
I searched hard for one, honestly, and the answer on two years of exchange bhavcopy data was no. Cash-and-carry peaked below one percent a month even before realistic slippage. Conversion arbitrage (the options-based equivalent) came out near zero. Dividend capture around record dates lost money. Several index option selling variants looked good until their worst months were included, at which point they ended below the risk-free rate. The 1.5 to 2 percent monthly target was not available from this family of trades at retail costs.
A follow-on search over 125,775 strategy and filter combinations, with a holdout period that was never touched during the search, kept exactly two rules alive, both volatility-based overnight and intraday rules rather than classic basis trades. Those two now run as a paper trader on real bid and ask prices every market day. Only that paper record will decide whether anything goes further, and the client was told so plainly.
How I built this: NSE Cash-and-Carry Arbitrage Scanner and Edge Search
The NSE cash-and-carry scanner is a read-only Python system on Angel One SmartAPI, and it was built in this order:
- Login and instrument hygiene. TOTP-based login, then the exchange instrument master is loaded and filtered: test contracts, stale expiries and symbols without a liquid near-month future are removed before any quote is requested.
- Pair construction. Each surviving stock is paired with its near-month future, and the target quantity is set from the book size so slippage modelling is realistic for the capital involved.
- Depth quotes. Five levels per side are pulled for both legs. Zero-bid and crossed markets are rejected as "no market".
- Executable basis. Buy-side VWAP through the cash asks and sell-side VWAP through the futures bids give the gross basis; the full cost stack and financing to expiry are subtracted; the result is annualised and compared to risk-free.
- Ranking and flags. Candidates are ranked on net annualised excess return, and any name with an unverified corporate action is flagged rather than hidden.
- Research harness. Two years of bhavcopy data drove the backtests that produced the negative verdict, after the two flattering bugs above were found and corrected.
- Paper trader. The two surviving rules from the 125,775-combination search are journaled daily by a scheduled task on real bid/ask prices.
The decisions I would defend to anyone: executable depth pricing rather than last prices, a scanner that structurally cannot place orders, and reporting the negative result with the bugs that had hidden it. The outcome is a correct tool and a clear answer: at retail costs, the classic basis trade on NSE does not beat T-bills, and the only candidates still alive are being judged by a paper record rather than a backtest.
FAQ
How often should the scanner refresh?
Depth changes every second, but a basis worth trading persists for minutes, not milliseconds, because the edge is a carry rate rather than a latency race. Refreshing every 15 to 30 seconds across the universe is enough and stays within broker rate limits.
Can the scanner be made to trade automatically?
Technically yes, and the broker API supports it. I chose not to, because the research verdict did not justify it and because a mis-priced quote that slips through a filter would be executed instantly. A scanner that ranks and a human who decides is the right split until the paper record says otherwise.
Does this work for index futures against ETFs?
The same math applies, with the ETF's own tracking error and spread as additional costs. Index arbitrage is also the most crowded corner of the market, so the executable basis is usually tighter than single stocks.
What data do I need for backtesting?
Daily bhavcopy files for cash and derivatives from the exchange, a verified corporate-actions calendar, and the true expiry calendar for every month. The last two are where my own backtest went wrong first, so treat them as first-class inputs.
If you want a depth-based scanner or an honest edge search built for your own book and broker, tell me about it on the contact page.
Building something in this space? I ship trading automation, Pine Script, MQL5 EAs, and full-stack tools with source and docs.
Start a project →