Hi everyone,

I have an also that dynamically selects a few large cap stocks daily. Out of those, a few calculations are made to select 1 stock that I like. Then, at 9h33 AM, I get and filter all the options of that stock with this code:

def my_options(self): self.Debug("%%%%%%%%%%%%% my_options {}".format(self.Time)) for sid in self.buyList: contracts = self.OptionChainProvider.GetOptionContractList(sid, self.Time.date()) self.underlyingPrice = self.Securities[sid].Price self.otm_calls = [i for i in contracts if i.ID.OptionRight == OptionRight.Call and i.ID.StrikePrice - self.underlyingPrice > 0 and 15 < (i.ID.Date - self.Time).days < 45] if len(self.otm_calls) > 0: contract = sorted(sorted(self.otm_calls, key = lambda x: x.ID.Date), key = lambda x: x.ID.StrikePrice - self.underlyingPrice, reverse=True) if len(contracts) > 0: self.AddOptionContract(contracts[0], Resolution.Minute) self.Debug(contracts[0].Value) self.SetHoldings(contract[0], 0.1)

That code generates this error:

Runtime Error: In Scheduled Event 'EveryDay: 9.53', ValueError : operands could not be broadcast together with shapes (8,2) (0,0) ValueError : operands could not be broadcast together with shapes (8,2) (0,0) (Open Stacktrace)

which I beleive is caused by this: self.AddOptionContract(contracts[0], Resolution.Minute)

if I run the code without this line, I get this error:

307788 | 10:47:54: %%%%%%%%%%%%% my_options 2011-02-02 09:33:00 307789 | 10:47:54: DGX 110219C00022500 307791 | 10:47:54: Backtest Handled Error: DGX UU9HR896NECM|DGX R735QTJ8XC9X not found in portfolio. Request this data when initializing the algorithm.

Just wondering what I am missing.

Again, I couldnt find any documentation on selecting options dynamically.

Thanks a lot in advance !

 

Author