// --- 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
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.