INNER CODE UNIT · Python

OnData

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

    def OnData(self, data):

        ## If we're done warming up, and not invested, Sell a put.
        if (not self.IsWarmingUp) and (not self.Portfolio.Invested):
            if data.Bars.ContainsKey(self.symbol):
                self.SellAnOTMStrangle()

        ## If we're assigned stock sell/cover the shares immediatley
        # order = self.Transactions.GetOrderById(orderEvent.OrderId)
        # if order.Type == OrderType.OptionExercise:
        #     self.Liquidate(orderEvent.Symbol.Underlying)

        ## If we're in a trade, check to see if we're at 50% gain or 200% loss on the position
        # for holding in self.Portfolio:
        #     if holding.Invested:
        #         unrealized_pnl_percent = holding.UnrealizedProfitPercent
        #         if unrealized_pnl_percent >= 50:
        #             self.Liquidate(holding.Symbol)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…