Overall Statistics
import pandas as pd

class SquareRedOrangeAntelope(QCAlgorithm):

#https://www.quantconnect.com/tutorials/introduction-to-options/quantconnect-options-api

    def Initialize(self):
        self.SetStartDate(2020, 9, 25)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        equity = self.AddEquity("SPY", Resolution.Minute) # Add the underlying stock: Google
        option = self.AddOption("SPY", Resolution.Minute) # Add the option corresponding to underlying stock
        self.symbol = option.Symbol
        # self.AddEquity("SPY", Resolution.Minute)
        
        #filter the contracts with strikes between (market price - 150, market price +150), 0-4 DTE
        option.SetFilter(-150,150, timedelta(0), timedelta(4))

    def OnData(self,slice):
        optionchain = None
        for i in slice.OptionChains:
            if i.Key != self.symbol: continue
            optionchain = i.Value
            self.Log("underlying price:" + str(optionchain.Underlying.Price))
        df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
               index=[x.Symbol.Value for x in optionchain],
               columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price'])
        self.Log(str(df))
      
      #stuck on error https://gis.stackexchange.com/questions/392239/help-solving-runtime-error-typeerror-nonetype-object-is-not-iterable
      
        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)