Overall Statistics |
Total Trades 9425 Average Win 0.07% Average Loss -0.07% Compounding Annual Return 8.490% Drawdown 19.800% Expectancy -0.013 Net Profit 13.316% Sharpe Ratio 0.407 Loss Rate 52% Win Rate 48% Profit-Loss Ratio 1.05 Alpha 0.448 Beta -21.17 Annual Standard Deviation 0.235 Annual Variance 0.055 Information Ratio 0.336 Tracking Error 0.235 Treynor Ratio -0.005 Total Fees $10200.09 |
### <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[:self.fineSymbols], 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