Overall Statistics |
Total Trades 4 Average Win 4.53% Average Loss -0.30% Compounding Annual Return 1.662% Drawdown 6.200% Expectancy 7.020 Net Profit 4.214% Sharpe Ratio 0.261 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 15.04 Alpha 0.032 Beta -1.028 Annual Standard Deviation 0.058 Annual Variance 0.003 Information Ratio -0.02 Tracking Error 0.058 Treynor Ratio -0.015 Total Fees $89.16 |
from System.Collections.Generic import List import numpy as np from QuantConnect.Data.UniverseSelection import * ### <summary> ### Basic template algorithm simply initializes the date range and cash. This is a skeleton ### framework you can use for designing an algorithm. ### </summary> class CANSLIM_ALGO(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(2016,1,4) #Set Start Date self.SetEndDate(2018,7,5) #Set End Date self.SetCash(100000) #Set Strategy Cash self.flag1 = 1 self.flag2 = 0 self.flag3 = 0 self.UniverseSettings.Resolution = Resolution.Daily self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction) self.AddEquity('SPY') self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY"), Action(self.Rebalancing)) # Find more symbols here: http://quantconnect.com/data self.__numberOfSymbols = 1500 self._changes = None self.Debug("numpy test >>> print numpy.pi: " + str(np.pi)) # sort the data by daily dollar volume and take the top 'NumberOfSymbols' def CoarseSelectionFunction(self, coarse): if self.flag1: CoarseWithFundamental = [x for x in coarse if (x.HasFundamentalData) and (float(x.Price) > 5)] sortedByDollarVolume = sorted(CoarseWithFundamental, key=lambda x: x.DollarVolume, reverse=True) top = sortedByDollarVolume[:self.__numberOfSymbols] return [i.Symbol for i in top] else: return [] def FineSelectionFunction(self, fine): if self.flag1: self.flag1 = 0 self.flag2 = 1 filtered_fine = [x for x in fine if (x.EarningReports.BasicEPS.ThreeMonths != 0) and (x.EarningReports.BasicEPS.SixMonths !=0) and ((x.EarningReports.BasicEPS.ThreeMonths - x.EarningReports.BasicEPS.SixMonths)/ (x.EarningReports.BasicEPS.SixMonths)) *100 > 25] filtered_fine = [x for x in filtered_fine if x.OperationRatios.ROE.ThreeMonths > 0.17] filtered_fine = [x for x in filtered_fine if (x.FinancialStatements.IncomeStatement.TotalRevenue.ThreeMonths !=0) and (x.FinancialStatements.IncomeStatement.TotalRevenue.SixMonths !=0) and ((x.FinancialStatements.IncomeStatement.TotalRevenue.ThreeMonths -x.FinancialStatements.IncomeStatement.TotalRevenue.SixMonths)/ (x.FinancialStatements.IncomeStatement.TotalRevenue.SixMonths)) >0.20] self.flag3 = self.flag3 + 1 # take the stock symbols return [x.Symbol for x in filtered_fine] else: return [] def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' if self.flag3 > 0: if self.flag2 == 1: self.flag2 = 0 # if we have no changes, do nothing if self._changes is None: return # liquidate removed securities for security in self._changes.RemovedSecurities: if security.Invested: self.Liquidate(security.Symbol) self.Log("Sell security" + str(security.Symbol.Value)) for security in self._changes.AddedSecurities: if security.Symbol.Value != "SPY": self.SetHoldings(security.Symbol, 1.0/float(len(self._changes.AddedSecurities))) self.Log("Buy security" + str(security.Symbol.Value)) self._changes = None # this event fires whenever we have changes to our universe def OnSecuritiesChanged(self, changes): self._changes = changes def Rebalancing(self): self.flag1 = 1 # Your New Python File