Hi Shile Wen, after following your and Arthur's suggestions, I was more or less able to run backtests on the algorithm with relatively no more issues. However, when deploying the algorithm live, I've been encountering a different issue. Everyday at around 11:30, the live deployment has been producing the error below most likely due to an overload of history requests:
Error:
Runtime Error: Algorithm took longer than 10 minutes on a single time loop. CurrentTimeStepElapsed: 10.0 minutes
Most likely from this code:
for security in sortedByDollarVolume:
symbol = security.Symbol
if symbol not in self.averages:
history = algorithm.History(symbol, 200, Resolution.Daily)
self.averages[symbol] = SelectionData(history)
self.averages[symbol].update(algorithm.Time, security.AdjustedPrice)
selected[symbol] = security.DollarVolume
Too many history requests. This is within the CoarseFilter function. An obvious solution would be to move the history request to the FineFilter function so that there is a significantly lower number of securities to request history for, but like Arthur said above, AdjustedPrice is not available in FineFundamental. So, moving the history request to FineFilter produces another different error:
Runtime Error: AttributeError : 'FineFundamental' object has no attribute 'AdjustedPrice'
at <lambda> in FundamentalUniverseSelectionModel.py:46
AttributeError : 'FineFundamental' object has no attribute 'AdjustedPrice' (Open Stacktrace)
A suggestion I received from someone else was to save AdjustedPrice from Coarse in a class variable dictionary so that it may also be used in FineFilter. I'm not exactly sure how to do that, but I tried it like this; I saved it in Coarse like:
self.AdjustedPrice = {x.Symbol:x.AdjustedPrice for x in sortedByDollarVolume}
Then attempted to use it in Fine like:
for security in sortedByDollarVolume:
symbol = security.Symbol
if symbol not in self.averages:
history = algorithm.History(symbol, 200, Resolution.Daily)
self.averages[symbol] = SelectionData(history)
self.averages[symbol].update(algorithm.Time, self.AdjustedPrice)
selected[symbol] = security.DollarVolume
But now end up with this error:
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 Update method. Please checkout the API documentation.
at <lambda> in FundamentalUniverseSelectionModel.py:46
TypeError : No method matches given arguments for Update (Open Stacktrace)