Overall Statistics Total Trades9512Average Win0.07%Average Loss-0.07%Compounding Annual Return14.862%Drawdown19.300%Expectancy0.019Net Profit21.222%Sharpe Ratio0.608Loss Rate51%Win Rate49%Profit-Loss Ratio1.06Alpha0.378Beta-14.219Annual Standard Deviation0.234Annual Variance0.055Information Ratio0.537Tracking Error0.234Treynor Ratio-0.01Total Fees\$10337.44
```### <summary>
### Demonstration of using coarse and fine universe selection together to filter down a smaller universe of stocks.
### </summary>
class CoarseFundamentalTop5Algorithm(QCAlgorithm):

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

self.SetStartDate(2014,01,01)  #Set Start Date
self.SetEndDate(2016,01,01)    #Set End Date
self.SetCash(100000)            #Set Strategy Cash

# what resolution should the data *added* to the universe be?
self.UniverseSettings.Resolution = Resolution.Daily

# this add universe method accepts a single parameter that is a function that
# accepts an IEnumerable<CoarseFundamental> and returns IEnumerable<Symbol>

self.__numberOfSymbols = 200
self._changes = SecurityChanges.None
self.fineSymbols = 50
self.fineSymbols2 = 25

# sort the data by daily dollar volume and take the top 'NumberOfSymbols'
def CoarseSelectionFunction(self, coarse):
# sort descending by daily dollar volume
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)

# return the symbol objects of the top entries from our sorted collection
return [ x.Symbol for x in sortedByDollarVolume[:self.__numberOfSymbols] ]

def FineSelectionFunction(self, fine):
sortedByEVEBITDA = sorted(fine, key=lambda x: x.ValuationRatios.EVToEBITDA, reverse=True)
sortedByPricetoBook = sorted(sortedByEVEBITDA, key = lambda x: x.ValuationRatios.PriceToBook, reverse=True)
return [x.Symbol for x in sortedByPricetoBook[:self.fineSymbols2]]

def OnData(self, data):
# if we have no changes, do nothing
if self._changes == SecurityChanges.None: return

# liquidate removed securities
for security in self._changes.RemovedSecurities:
if security.Invested:
self.Liquidate(security.Symbol)

# we want 20% allocation in each security in our universe