Hey,
I have a universe where I add stocks and options. in OnData I have to access both of the symbols at the same time, so I did a lookup dictionary. The problem is when I try to access the values(optinos symbol) in the dictionary for each stock symbol. When debugging the code i get the value I need but in the code it always throws me an error message.
def SelectCoarse(self, coarse):
#---------------Parameters (not implemented yet) + adding tickers for testing------------#
tickers = ["AAPL", "IBM"]
symbols = [Symbol.Create(x, SecurityType.Equity, Market.USA) for x in tickers]
for x in symbols:
self.all_symbols.setdefault(x, [])
option = self.AddOption(x)
self.all_symbols.setdefault(x).append(option.Symbol)
option.SetFilter(0, +5, timedelta(0), timedelta(60))
return symbols
#---> 'AAPL' : '?AAPL'
I have to acces both because I did some calculations with the stock symbols. For each stock I then have to acces the options symbol to check if it is invested or not(Option).
#OnData
for symbol in self.all_symbols:
if self.Portfolio[self.all_symbols[symbol]].Invested and bool(self.future_dates[symbol]) is True:
if self.Time > self.future_dates[symbol][0]:
self.Liquidate(self.all_symbols[symbol])
del self.future_dates[symbol][0]
if not self.Portfolio[self.all_symbols[symbol]].Invested and bool(self.future_dates[symbol]) is True:
if (self.Time >= (self.future_dates[symbol][0] - timedelta(days=self.days[symbol])) and self.first_time == True and self.Time < self.future_dates[symbol][0]):
chains = data.OptionChains.get(self.all_symbols[symbol])
self.TradeOptions(chains)
self.Debug("stock name: " + str(symbol.Value))
self.Debug("Option name: " + str(self.all_symbols[symbol].Value))
Error Code:
Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'list'>) method.
Does somebody know how to fix this problem?
Louis Szeto
Hi Nico
For this line:
It only takes an argument of type Symbol, but not a list of Symbol. You'll have to do a for-loop iteration:
Refer to this docs for details.
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Nico Xenox
Hey Louis Szeto
Thank you i changed that code a while ago. My question is how to adjust this line of code:
My lookup table looks the following:
AAPL: ?AAPL
Now im trying to check if the option of this symbol is invested but when I use the line of code I have above it will be empty because it has a key I cant access.
If I use this one:
It will never say that the option is invested because it acces the symbol (stock) and not an option.
How can I change that?
Nico Xenox
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!