// --- User Inputs --- buySide = input.string("Put", title="Buy Side (Put/Call)", options=["Call", "Put"]) sellSide = input.string("Put", title="Sell Side (Put/Call)", options=["Call", "Put"]) spreadWidth = input.int(50, title="Width of the Spread (Strike Difference)", minval=1) optionIV = input.float(0.20, title="Implied Volatility (IV) Approx.", minval=0.01, maxval=5) // Placeholder for IV numContracts = input.int(1, title="Number of Contracts", minval=1) // SPX options are cash-settled, so we can track number of contracts expirationDate = input.string("2024-01-19", title="Expiration Date (yyyy-mm-dd)") // Placeholder for expiration date
// --- SPX Specific Adjustments --- spxPrice = close // SPX spot price (current price) spxMultiplier = 100 // SPX options multiplier for cash-settled contracts
// --- Simplified Premium Calculation (Using IV and Price) --- // Approximation for premiums based on IV buyPremium = optionIV * 0.5 * buyStrike / 100 // Simplified calculation for buy option premium sellPremium = optionIV * 0.5 * sellStrike / 100 // Simplified calculation for sell option premium
// --- Net Credit / Debit Calculation --- netPremium = sellPremium - buyPremium maxProfit = netPremium * spxMultiplier * numContracts // Maximum profit is the net premium times the SPX multiplier and contracts maxLoss = (sellStrike - buyStrike) * spxMultiplier * numContracts - maxProfit // Maximum loss is the strike difference minus the premium received
// --- Profit/Loss Calculation for Various Underlying Prices --- pl = 0.0 if (buySide == "Put" and spxPrice < buyStrike) pl := maxProfit - (buyStrike - spxPrice) * spxMultiplier * numContracts else if (sellSide == "Put" and spxPrice < sellStrike) pl := maxProfit - (sellStrike - spxPrice) * spxMultiplier * numContracts else pl := maxProfit