We have made an improvement in the Universe Selection feature that addresses one complaint that python quants have made. Up to now, we were forced to create a C# List of Symbol object, populate it with the Symbol member of the universe and finally return the list:
def CoarseSelectionFunction(self, coarse):
'''Take the top 50 by dollar volume using coarse'''
# sort descending by daily dollar volume
sortedByDollarVolume = sorted(coarse, \
key=lambda x: x.DollarVolume, reverse=True)
# we need to return only the symbol objects
list = List[Symbol]()
for x in sortedByDollarVolume[:50]: list.Add(x.Symbol)
return list
With the update, we can return a list which is more python friendly:
def CoarseSelectionFunction(self, coarse):
'''Take the top 50 by dollar volume using coarse'''
# sort descending by daily dollar volume
sortedByDollarVolume = sorted(coarse, \
key=lambda x: x.DollarVolume, reverse=True)
# we need to return only the symbol objects
return [ x.Symbol for x in sortedByDollarVolume[:50] ]
Unfortunately, we were not able to support back compatibility and this change will "break" algorithms that rely on the former return type. The following runtime error message will be shown:
20170926 14:29:42 ERROR:: Runtime Error: Python.Runtime.ConversionException: could not convert Python result to System.Object[]
Meaning that pythonnet could not convert the List<Symbol> into System.Object[] which is the python list.