Hi Everyone,
I am attempting to create a Universe Selection that coarses through momentum by checking if a current stock price is above the 50 and 200 Daily SMAs, and then taking up to the ten highest market cap of these stocks and using a random forest regression to portfolio balance them. Unfortunately I keep running into the error:
Runtime Error: Update() missing 1 required positional argument: 'value' at SelectCoarse avg.Update(cf) at Python.Runtime.PythonException.ThrowLastAsClrException() at Python.Runtime.Dispatcher.TrueDispatch(Object[] args) at Python.Runtime.Dispatcher.Dispatch(Object[] args) at __System_Func`2\[\[System_Collections_Generic_IEnumerable`1\[\[QuantConnect_Data_UniverseSelection_CoarseFundamental\ in main.py: line 55,
and haven't been able to resolve this issue on my own. Does anyone know how I could edit the update code at the end of main.py to avoid this? It looks like this:
# region imports
from AlgorithmImports import *
from alpha import RandomForestAlphaModel
from portfolio import MeanVarianceOptimizationPortfolioConstructionModel
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
# endregion
class RandomForestAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2012, 1, 1)
self.SetCash(100000)
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
self.AddEquity("SPY", Resolution.Daily)
self.SetBenchmark("SPY")
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw
self.AddUniverse(self.SelectCoarse)
self.AddAlpha(RandomForestAlphaModel(
self,
self.GetParameter("minutes_before_close", 5),
self.GetParameter("n_estimators", 100),
self.GetParameter("min_samples_split", 5),
self.GetParameter("lookback_days", 360)
))
self.SetPortfolioConstruction(MeanVarianceOptimizationPortfolioConstructionModel(self, lambda time: None, PortfolioBias.Long, period=self.GetParameter("pcm_periods", 5)))
self.AddRiskManagement(NullRiskManagementModel())
self.SetExecution(ImmediateExecutionModel())
self.SetWarmUp(timedelta(200))
def __init__(self,
universeCount = 10,
universeSettings = None):
self.universeCount = universeCount
# holds our coarse fundamental indicators by symbol
self.averages = {}
def SelectCoarse(self, coarse):
filtered = []
# We are going to use a dictionary to refer the object that will keep the moving averages
for cf in coarse:
if cf.Symbol not in self.averages:
self.averages[cf.Symbol] = SymbolData(cf.Symbol)
# Updates the SymbolData object with current EOD price
avg = self.averages[cf.Symbol]
avg.Update(cf)
# Filter the values of the dict: wait for indicator to be ready
filtered_values = filter(lambda x: (x.is_ready and x.Price.Current.Value > x.SlowSma.Current.Value), self.averages.values())
filtered_values = filter(lambda x: (x.is_ready and x.Price.Current.Value > x.FastSma.Current.Value), self.averages.values())
filtered = sorted(filtered, key=lambda avg: x.Market, reverse = True)
self.filtered_coarse = [x.Symbol for x in filtered[:self.universeCount]]
return self.filtered_coarse
class SymbolData(object):
def __init__(self, symbol):
self.Symbol = symbol
self.Price = SimpleMovingAverage(1)
self.SlowSma = SimpleMovingAverage(200)
self.FastSma = SimpleMovingAverage(50)
def Update(self, time, value):
return self.Price.Update(time, value)
return self.SlowSma.Update(time, value)
return self.FastSma.Update(time, value)
Nico Xenox
Hey David Liu,
Instead of using “avg.Update(cf)” on line 56 try using “avg.Update(cf.EndTime, cf.AdjustedPrice)” this should solve the issue you're having.
Hope it helps
Best,
Nico
David L
Thank you Nico! That fixed the problem and it can run now.
David L
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!