Hello,

I am trying to us the option chain provider to to give me all options contracts that exist for a given underlying at the algorithm time. I then want to sort these contracts by those with an expiration date on the coming Friday. I then want to subscribe to all these contracts and add them to my universe. However, when I try to do math on my list of contracts that I am supposed to be subscribed to, I get an error saying that the list of contracts is empty. What is the correct way to subscribe to these contracts? Code attached.

Thanks,

Ian

import datetime import numpy as np class QuantumOptimizedCoreWave(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 11, 29) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.equity = self.AddEquity("SPY", Resolution.Minute) self.equity.SetDataNormalizationMode(DataNormalizationMode.Raw) def OnData(self, data): contracts = self.OptionsFilter(data) for contract in contracts: if contract.Right == 1: strike_prices = np.append(strike_prices, contract.Strike) call_open_interest = np.append(call_open_interest, contract.OpenInterest) if contract.Right == 0: put_open_interest = np.append(put_open_interest, contract.OpenInterest) put_minimum_OI = np.argmin(put_open_interest) # I am getting an argmin error on an empty list def OptionsFilter(self, data): selected = [] contracts = self.OptionChainProvider.GetOptionContractList(self.equity.Symbol, data.Time) # Gets every options contract available for the underlying symbol at that time d = self.Time while d.weekday() != 4: # Trying to find contracts with expiration on the coming Friday d += datetime.timedelta(1) # d = d + timedelta(7) # finds the contracts expiring in two weeks instead of one for contract in contracts: if contract.Expiry == d: selected.append(contract) # Supposed to append contracts that expire the coming Friday for contract in selected: self.AddOptionContract(contract, Resolution.Minute) # Supposed to subscribe to all contracts in list return selected # Supposed to return the list of selected contracts

 

Author