Hi All, 

I have spent the last few months working through the issue dealing with bad performance on option strategies and wanted to give people back the knowledge that i have worked out to increase my options strategy speeds whilst still being able to filter and sort for things other than strikes and expiry.

so firstly the solution that most people will already know is that in order to keep the performance high, you need to keep your universe very small, this means that you need to use get options contract instead of subscribing to all your options chains in the initialize area. as many have pointed out in other topics, this has the drawback of only being able to filter on strikes and expiry's and option types which removes functionality for people.

The solution is to use get options contract to filter for type, strikes and expiry's and then to manually subscribe to the options using add security, then filter and sort the options to find the one you want and then do manually unsubscribe from all others. to illustrate this is have created the code block below which first filters using the standard get options contract, and then uses a custom sorting function to filter on things like bidprice and askprice. using the same workflow, it should be easy for others to run secondary filtration for thing such as option greeks or prices.

My code for reference:

    def GetOption(self,slice,underlying,optionright,MinStrike,MaxStrike,MinExpiry,MaxExpiry,sortedfunction,reverse):
       contracts = self.OptionChainProvider.GetOptionContractList(underlying, self.Time)  ## Get list of Options Contracts for a specific time
       if len(contracts) == 0: return
   
       filtered_options = [x for x in contracts if   x.ID.OptionRight == optionright and\
                                                   x.ID.StrikePrice > MinStrike and\
                                                   x.ID.StrikePrice < MaxStrike and\
                                                   x.ID.Date > MinExpiry and\
                                                   x.ID.Date < MaxExpiry]
       
       if len(filtered_options) == 0: return
       added_contracts = []
       for x in filtered_options:
           option = self.AddOptionContract(x, Resolution.Minute)
           optionsymbol = self.Securities[option.Symbol]
           added_contracts.append(optionsymbol)
       
       sorted_options = sorted(added_contracts,key = sortedfunction, reverse = reverse)
       
       selected = sorted_options[0]
       
       for x in sorted_options:
           if x != selected:
               self.RemoveSecurity(x.Symbol)
       return selected