Academy/Strategy Code Breakdown/Iron Condor — Code Walkthrough
Strategy Code BreakdownLesson 8

Iron Condor — Code Walkthrough

Walk through the four-legged options structure: how the call spread and put spread are combined, how breakevens are computed, and why net delta near zero is the goal.

15 minute read
4 key takeaways

Iron Condor — Code Walkthrough

The iron condor is the quintessential options income strategy — neutral, defined-risk, and designed to profit from time decay when a stock moves sideways. It has four legs: two calls (a spread) and two puts (a spread). This Python walkthrough covers every part of the implementation.

Step 1 — Four-Strike Configuration

python
class IronCondorStrategy:
    def __init__(
        self,
        call_short_offset:  float = 0.05,  # short call 5% above spot (sell here)
        call_long_offset:   float = 0.10,  # long call 10% above spot (buy here, cap loss)
        put_short_offset:   float = -0.05, # short put 5% below spot (sell here)
        put_long_offset:    float = -0.10, # long put 10% below spot (buy here, cap loss)
        days_to_expiry:     int   = 45,    # 45 DTE is a common sweet-spot for theta
        risk_free_rate:     float = 0.05,
        implied_volatility: Optional[float] = None,
        contracts:          int   = 1,
        crr_steps:          int   = 100,
    ):

Why 45 Days to Expiry?

Theta decay (time value erosion) is not linear — it accelerates dramatically in the last 30 days. Many iron condor traders open at 45 DTE and close at 21 DTE to capture the fastest theta while reducing gamma risk from large moves.

Step 2 — evaluate(): Pricing All Four Legs

python
def evaluate(self, spot_price, historical_vol=0.20):
    sigma = self.implied_volatility or historical_vol
    T     = self.days_to_expiry / 365.0

    # The four strikes
    cs = round(spot_price * (1 + self.call_short_offset), 2)  # short call (sell)
    cl = round(spot_price * (1 + self.call_long_offset),  2)  # long call (buy)
    ps = round(spot_price * (1 + self.put_short_offset),  2)  # short put (sell)
    pl = round(spot_price * (1 + self.put_long_offset),   2)  # long put (buy)

    # Bear call spread: sell cs, buy cl → receive a credit
    call_credit = (crr_price(spot_price, cs, T, r, sigma, 'call') -
                   crr_price(spot_price, cl, T, r, sigma, 'call')) * contracts * 100

    # Bull put spread: sell ps, buy pl → receive a credit
    put_credit  = (crr_price(spot_price, ps, T, r, sigma, 'put') -
                   crr_price(spot_price, pl, T, r, sigma, 'put'))  * contracts * 100

    net_credit   = call_credit + put_credit   # total income received
    spread_width = (cl - cs) * contracts * 100
    max_profit   = net_credit
    max_loss     = spread_width - net_credit  # worst case: one wing goes to max width
LegActionWhy
Short call (cs, +5%)SellCollect premium; lose if stock rallies above this
Long call (cl, +10%)BuyCap loss if stock blows past cs — defines max loss
Short put (ps, −5%)SellCollect premium; lose if stock falls below this
Long put (pl, −10%)BuyCap loss if stock crashes past ps — defines max loss

Step 3 — Breakeven Calculations

python
# Upper breakeven: short call strike + net credit per share
# If stock closes above this at expiry → net loss
upper_be = cs + net_credit / (self.contracts * 100)

# Lower breakeven: short put strike - net credit per share
# If stock closes below this at expiry → net loss
lower_be = ps - net_credit / (self.contracts * 100)

# The "profit zone" — stock must stay inside this range
profit_zone_width = upper_be - lower_be

The net credit effectively widens your profit zone. If you collect $2.00 credit on a $5-wide condor, you only need the stock to stay within ±$2 of the short strikes, not ±$0.

Step 4 — greeks(): Net Delta Approximation

python
def greeks(self, spot_price, historical_vol=0.20):
    dS = spot_price * 0.01

    def net_price(s):
        # Net value of the condor at spot price s:
        # We're SHORT cs call, LONG cl call, SHORT ps put, LONG pl put
        # Short = negative (we collected money), Long = positive (we paid money)
        return (
            - crr_price(s, cs, ..., 'call')  # short call: negative position
            + crr_price(s, cl, ..., 'call')  # long call: positive position
            - crr_price(s, ps, ..., 'put' )  # short put: negative position
            + crr_price(s, pl, ..., 'put' )  # long put: positive position
        )

    pu, pd = net_price(spot + dS), net_price(spot - dS)
    base   = net_price(spot)
    return {
        'net_delta': (pu - pd) / (2 * dS),  # ~0 when balanced
        'net_gamma': (pu - 2 * base + pd) / dS**2  # negative (hurt by large moves)
    }

Negative Gamma is the Risk

Iron condors have negative net gamma — large moves hurt you disproportionately. This is why managing the position when the stock nears a short strike is critical. A 2-sigma move against you can turn a max-profit setup into a max-loss.

Putting It All Together

The iron condor combines two credit spreads into one position. You receive income upfront (max profit) in exchange for taking on defined risk on either side. The model prices all four legs separately using the same CRR tree, then nets the positions — keeping the math clean and auditable.

Key Takeaways
  • An iron condor = bear call spread + bull put spread sold simultaneously
  • You collect two credits; profit when underlying stays inside the short strikes
  • Max loss = spread width − net credit, on either wing
  • Net delta should be near zero — the strategy is directionally neutral

Open Iron Condor in Lab

Clone and analyze the iron condor strategy