I was wondering if anyone had any tips on how to speed up universe selection.
Also, in CourseFilter, I return an empty list if it is not a new month. I did this in hopes that fine data would not be collected in the FineFilter function. Is my thought process here correct?
Here is my code.
def CoarseFilter(self, coarse):
if self.Time.month == self.lastMonth:
return []
CoarseWithFundamental = [x for x in coarse if x.HasFundamentalData and x.DollarVolume > 10000000]
sortedByDollarVolume = sorted(CoarseWithFundamental, key=lambda x: x.DollarVolume, reverse=False)
return [i.Symbol for i in sortedByDollarVolume[:500]]
def FineFilter(self, fine):
if self.Time.month == self.lastMonth:
return self.symbols
self.lastMonth = self.Time.month
fine = [x for x in fine if x.ValuationRatios.PERatio > 0]
sortedPERatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio)
self.symbols = [x.Symbol for x in sortedPERatio[:50]]
return self.symbols