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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user