These scripts place neutral options trades on Nifty 50 using the Upstox Python SDK. Use them when you think the market is going to stay in a range — not move up or down significantly.
Before running: Replace ACCESS_TOKEN in each file with your Upstox access token.
Works on any index: Change
"Nifty 50"insearch_instrument()to trade a different index — e.g."Nifty Bank"for Bank Nifty or"SENSEX"for BSE Sensex.
When to use: You expect Nifty to barely move from its current level — low volatility, sideways market.
What it does: Sells both an ATM call and an ATM put at the same strike. You collect premium from both sides. As long as the market stays close to that strike, both options lose value and you profit. If the market moves sharply in either direction, losses can be large.
Think of it as betting that “nothing big will happen.” You earn money from time decay as long as the market stays calm.
Example:
You profit when : Nifty closes between 22,820 and 23,380
Max profit : ₹280 per unit — if Nifty closes exactly at 23,100
Max loss : Grows if Nifty moves far beyond either breakeven — no hard cap
Note: This strategy has unlimited risk on both sides. Use it only when you are confident the market will stay range-bound, or consider Iron Butterfly for a safer version.
Run:
python3 code/short_straddle.py
When to use: Similar to the straddle, but you are okay giving the market a bit more room to move. You expect Nifty to stay within a wider range.
What it does: Sells an OTM call (one strike above ATM) and an OTM put (one strike below ATM). Since both options are out-of-the-money, less premium is collected compared to a straddle — but the market has more breathing room before the trade starts losing.
Example:
You profit when : Nifty closes between 22,845 and 23,355
Max profit : ₹205 per unit — if Nifty stays between the two sold strikes
Max loss : Grows if Nifty moves far beyond either breakeven — no hard cap
Straddle vs Strangle: Strangle gives more room for the market to move but earns less premium. Straddle earns more but needs the market to stay very close to ATM.
Run:
python3 code/short_strangle.py
When to use: You expect Nifty to stay near its current level, but you want your losses to be capped — unlike the straddle where losses are unlimited.
What it does: Sells an ATM call and an ATM put (just like a straddle) to collect premium, but also buys an OTM call and an OTM put further away as protection. The bought options limit how much you can lose if the market moves sharply. You collect less premium overall, but your risk is fully defined.
Example:
You profit when : Nifty closes between 22,935 and 23,265
Max profit : ₹165 per unit — if Nifty closes at 23,100
Max loss : Capped — cannot lose more than (wing width − net credit)
Why use this over a Straddle? The Iron Butterfly is safer — your loss is always limited. Great for beginners stepping into neutral strategies.
Run:
python3 code/iron_butterfly.py
When to use: You expect Nifty to stay range-bound but want two profit zones instead of one — one above and one below the current price. All risk is defined.
What it does: Combines a call butterfly and a put butterfly around the ATM strike. A butterfly spread makes money when the market closes near the middle strike of that butterfly. By building one on the call side and one on the put side, you create two peaks of profit — one slightly above ATM and one slightly below. The profit and loss zone resembles the Batman logo, giving the strategy its name.
You pay a small net premium to enter. Your loss cannot exceed that premium, no matter what the market does.
Legs breakdown:
Example:
Profit zones : Near ATM+1 (call butterfly peak) and ATM-1 (put butterfly peak)
Max profit : Varies — roughly 2–4× the net cost, at each inner strike
Max loss : Net premium paid ≈ ₹15 per unit — fully defined, cannot lose more
Why Batman? It’s a low-cost, defined-risk strategy with two profit opportunities. Good when you expect the market to be slightly volatile but within a band.
Run:
python3 code/batman.py
When to use: You expect Nifty to stay within a range — wider than a straddle, with fully capped risk on both sides. One of the most popular neutral strategies among options traders.
What it does: Sells an OTM call (ATM+1) and an OTM put (ATM-1) to collect premium, then buys a further OTM call (ATM+2) and put (ATM-2) as wings to cap the maximum loss. You collect net premium upfront. As long as Nifty stays between the two short strikes, both short options expire worthless and you keep the full premium. If Nifty breaks out, the long wings limit how much you can lose.
Think of it as a short strangle with insurance. You give up a little premium to buy the wings, but in return your loss is always capped — no matter how far the market moves.
Example:
You profit when : Nifty closes between 22,960 and 23,240 (short strikes ± net credit)
Max profit : ₹90 per unit — if Nifty closes between 23,050 and 23,150
Max loss : Wing width − Net credit = 50 − 90 → capped at wing boundary
Iron Condor vs Short Strangle: The condor collects less premium but gives you defined, capped risk. The strangle earns more but has unlimited loss potential. For most traders, the condor is the safer, more manageable choice.
Run:
python3 code/short_iron_condor.py