I think my FineSelectionFunction is pretty simple. First, I filter for securities with more than zero shares and then I filter for net net stocks. For some reason, I get the error:

Runtime Error: Algorithm took longer than 10 minutes on a single time loop. CurrentTimeStepElapsed: 10.0 minutes

Why is this happening? My code is below.

from Execution.ImmediateExecutionModel import ImmediateExecutionModel from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel class NetNet(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 1, 1) # Set Start Date self.SetEndDate(2020, 1, 31) self.SetCash(100000) # Set Strategy Cash self.SetAlpha(NetNetAlpha()) self.SetExecution(ImmediateExecutionModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(lambda time: None)) self.Settings.RebalancePortfolioOnInsightChanges = False self.Settings.RebalancePortfolioOnSecurityChanges = True self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction, self.FineSelectionFunction, None, None)) self.UniverseSettings.Resolution = Resolution.Daily self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw)) def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' # if not self.Portfolio.Invested: # self.SetHoldings("SPY", 1) # on 15 Jan, filter for securities with fundamental data def CoarseSelectionFunction(self, coarse): if self.Time.month == 1 and self.Time.day == 15: filtered = [ x.Symbol for x in coarse if x.HasFundamentalData ] return filtered else: return Universe.Unchanged # on 15 Jan, filter first for securities with shares and then filter a second time for net net stocks def FineSelectionFunction(self, fine): # filtered = [ x.Symbol for x in fine if (x.FinancialStatements.BalanceSheet.CurrentAssets.ThreeMonths - x.FinancialStatements.BalanceSheet.TotalLiabilitiesAsReported.ThreeMonths) > 0 ] filtered = [ x.Symbol for x in fine if x.FinancialStatements.BalanceSheet.OrdinarySharesNumber.ThreeMonths > 0 ] filtered2 = [ x.Symbol for x in filtered if (x.Price / ((x.FinancialStatements.BalanceSheet.CurrentAssets.ThreeMonths - x.FinancialStatements.BalanceSheet.TotalLiabilitiesAsReported.ThreeMonths) / x.FinancialStatements.BalanceSheet.OrdinarySharesNumber.ThreeMonths)) <= 0.66 ] return filtered2 class NetNetAlpha(AlphaModel): def __init__(self): pass # self.lastMonth = -1 def OnSecuritiesChanged(self, algorithm, changes): pass def Update(self, algorithm, data): insights = [] if algorithm.Time.month == 1 and algorithm.Time.day == 15: for security in algorithm.ActiveSecurities.Values: # price = security.Price # currentAssets = security.Fundamentals.FinancialStatements.BalanceSheet.CurrentAssets.ThreeMonths # totalLiabilities = security.Fundamentals.FinancialStatements.BalanceSheet.TotalLiabilitiesAsReported.ThreeMonths # shares = security.Fundamentals.FinancialStatements.BalanceSheet.OrdinarySharesNumber.ThreeMonths # if ( price / ( (currentAssets - totalLiabilities) / shares ) <= 0.66 ): # insights.append(Insight.Price(security.Symbol, timedelta(days = 366), InsightDirection.Up)) insights.append(Insight.Price(security.Symbol, timedelta(days=366), InsightDirection.Up)) return insights else: return insights

 

Author