Improves Universe Selection for python

In python algorithm using Universe Selection, the selector method should return a List<Symbol>. To make it more pythonic, we allow returning python list. The conversion is, then, performed in C# side.
This commit is contained in:
AlexCatarino
2017-09-26 13:31:57 +01:00
parent 7d2a67c086
commit 3da8449fea
4 changed files with 20 additions and 48 deletions
@@ -58,14 +58,7 @@ class CoarseFineFundamentalComboAlgorithm(QCAlgorithm):
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
# return the symbol objects of the top entries from our sorted collection
top5 = sortedByDollarVolume[:self.__numberOfSymbols]
# we need to return only the symbol objects
list = List[Symbol](len(top5))
for x in top5:
list.Add(x.Symbol)
return list
return [ x.Symbol for x in sortedByDollarVolume[:self.__numberOfSymbols] ]
# sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
def FineSelectionFunction(self, fine):
@@ -73,14 +66,7 @@ class CoarseFineFundamentalComboAlgorithm(QCAlgorithm):
sortedByPeRatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=True)
# take the top entries from our sorted collection
topFine = sortedByPeRatio[:self.__numberOfSymbolsFine]
list = List[Symbol](len(topFine))
for x in topFine:
list.Add(x.Symbol)
return list
return [ x.Symbol for x in sortedByPeRatio[:self.__numberOfSymbolsFine] ]
def OnData(self, data):
# if we have no changes, do nothing
@@ -71,13 +71,11 @@ class EmaCrossUniverseSelectionAlgorithm(QCAlgorithm):
# Sorts the values of the dict: we want those with greater difference between the moving averages
values.sort(key=lambda x: x.scale, reverse=True)
# we need to return only the symbol objects
list = List[Symbol]()
for x in values[:self.coarse_count]:
self.Log('symbol: ' + str(x.symbol.Value) + ' scale: ' + str(x.scale))
list.Add(x.symbol)
return list
# we need to return only the symbol objects
return [ x.symbol for x in values[:self.coarse_count] ]
# this event fires whenever we have changes to our universe
def OnSecuritiesChanged(self, changes):
@@ -52,11 +52,7 @@ class UniverseSelectionRegressionAlgorithm(QCAlgorithm):
def CoarseSelectionFunction(self, coarse):
list = List[Symbol]()
for c in coarse:
if c.Symbol.Value == "GOOG" or c.Symbol.Value == "GOOCV" or c.Symbol.Value == "GOOAV" or c.Symbol.Value == "GOOGL":
list.Add(c.Symbol)
return list
return [ c.Symbol for c in coarse if c.Symbol.Value == "GOOG" or c.Symbol.Value == "GOOCV" or c.Symbol.Value == "GOOAV" or c.Symbol.Value == "GOOGL" ]
def OnData(self, data):