Algorithmic Trading & Indicators Intermediate

Multi-Leg Option Strategy Payoff & Breakeven Calculator in Python (Iron Condor / Straddle)

Model expiry P&L payoff curves, Max Profit, Max Loss, and exact Upper/Lower Breakeven points for Short Straddles, Strangles, and Iron Condors in Python.

#numpy#pandas

Problem Statement

Non-directional option writers need to verify net credit, margin risk-to-reward, and exact breakeven strikes before deploying 4-leg Iron Condors on weekly expiry.

Formula / Core Logic

Call Intrinsic at Expiry = max(0, Spot_T - Strike) Put Intrinsic at Expiry = max(0, Strike - Spot_T) Leg P&L = Direction * (Intrinsic - Premium_Paid)

Installation

pip install numpy pandas
short-straddle-iron-condor-payoff-calculator-python.py
import numpy as np
import pandas as pd

def option_strategy_payoff(legs, spot_range, lot_size=75):
    # legs format: [{'type': 'CE', 'strike': 24000, 'premium': 120, 'pos': -1}, ...]
    spots = np.linspace(spot_range[0], spot_range[1], 500)
    total_pnl = np.zeros_like(spots)
    
    for leg in legs:
        intrinsic = np.maximum(0, spots - leg['strike']) if leg['type'] == 'CE' else np.maximum(0, leg['strike'] - spots)
        leg_pnl = (intrinsic - leg['premium']) if leg['pos'] == 1 else (leg['premium'] - intrinsic)
        total_pnl += leg_pnl * abs(leg['pos']) * lot_size
        
    return {'Max_Profit': round(np.max(total_pnl), 2), 'Max_Loss': round(np.min(total_pnl), 2), 'Payoff_DF': pd.DataFrame({'Spot': spots, 'PnL': total_pnl})}

Get the Complete 100+ Python Quant & Automation Bundle

Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).

Buy Full Bundle on Gumroad ($19) →

Frequently Asked Questions

Q: How do I represent a Short Straddle in the `legs` list?

Pass two legs at the same ATM strike with `'pos': -1`—one with `'type': 'CE'` and one with `'type': 'PE'`.