INNER CODE UNIT · Python

InitOptionsAndGreeks

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

    def InitOptionsAndGreeks(self, theEquity):

        ## 1. Specify the data normalization mode (must be 'Raw' for options)
        theEquity.SetDataNormalizationMode(DataNormalizationMode.Raw)

        ## 2. Set Warmup period of at least 30 days
        self.SetWarmup(30, Resolution.Daily)

        ## 3. Set the security initializer to call SetMarketPrice
        self.SetSecurityInitializer(lambda x: x.SetMarketPrice(self.GetLastKnownPrice(x)))

        ## 4. Subscribe to the option feed for the symbol
        theOptionSubscription = self.AddOption(theEquity.Symbol)

        ## 5. set the pricing model, to calculate Greeks and volatility
        theOptionSubscription.PriceModel = OptionPriceModels.CrankNicolsonFD()  # both European & American, automatically

        ## 6. Set the function to filter out strikes and expiry dates from the option chain

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…