| Overall Statistics |
|
Total Trades 9512 Average Win 0.07% Average Loss -0.07% Compounding Annual Return 14.862% Drawdown 19.300% Expectancy 0.019 Net Profit 21.222% Sharpe Ratio 0.608 Loss Rate 51% Win Rate 49% Profit-Loss Ratio 1.06 Alpha 0.378 Beta -14.219 Annual Standard Deviation 0.234 Annual Variance 0.055 Information Ratio 0.537 Tracking Error 0.234 Treynor Ratio -0.01 Total 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.AddUniverse(self.CoarseSelectionFunction)
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
for security in self._changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.039)
self._changes = SecurityChanges.None;
# this event fires whenever we have changes to our universe
def OnSecuritiesChanged(self, changes):
self._changes = changes