INNER CODE UNIT · Python

SellAnOTMStrangle

ldt9/PyOptionTrader · research/backtesting/QuantConnect.py:75

    def SellAnOTMStrangle(self):

        ## Sell a 16 delta strangle expiring in 45 days
        putContract = self.SelectContractByDelta(self.equity.Symbol, .16, 45, OptionRight.Put)
        callContract = self.SelectContractByDelta(self.equity.Symbol, .16, 45, OptionRight.Call)

        ## construct an order message -- good for debugging and order records
        orderMessage = f"Stock @ ${self.CurrentSlice[self.equity.Symbol].Close} | " + f"Sell {putContract.Symbol} " + f"({round(putContract.Greeks.Delta, 2)} Delta)" + f" | Sell {callContract.Symbol} " + f"({round(callContract.Greeks.Delta, 2)} Delta)"
        self.Debug(f"{self.Time} {orderMessage}")

        ## Create Legs for the trade to avoid entering only one leg open at a time
        legs = [
            Leg.Create(callContract.Symbol, -1),
            Leg.Create(putContract.Symbol, -1)
        ]
        self.ComboMarketOrder(legs, 1, False, orderMessage)

    ## Get an options contract that matches the specified criteria:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…