Overall Statistics |
Total Trades 82 Average Win 0.31% Average Loss -0.14% Compounding Annual Return -6.867% Drawdown 2.300% Expectancy -0.373 Net Profit -2.159% Sharpe Ratio -2.579 Probabilistic Sharpe Ratio 2.324% Loss Rate 80% Win Rate 20% Profit-Loss Ratio 2.21 Alpha -0.058 Beta -0.004 Annual Standard Deviation 0.022 Annual Variance 0 Information Ratio 0.289 Tracking Error 0.497 Treynor Ratio 14.546 Total Fees $197.47 |
class CalibratedUncoupledCoreWave(QCAlgorithm): def Initialize(self): self.SetStartDate(2020,1, 1) # Set Start Date #self.SetEndDate(2016, 12, 12) # Set End Date self.SetCash(100000) # Set Strategy Cash self.UniverseSettings.Resolution = Resolution.Minute self.AddUniverse(self.SelectCoarse,self.SelectFine) self.SetExecution( NullExecutionModel() ) self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday, DayOfWeek.Tuesday,DayOfWeek.Wednesday, DayOfWeek.Thursday,DayOfWeek.Friday), self.TimeRules.At(15, 30), self.ClosePositions) self.coarseclose={} self.fineclose={} self.traded={} self.targetentry=2 def SelectCoarse(self, coarse): myuniverse = [x for x in coarse if x.HasFundamentalData and x.DollarVolume > 0 \ and x.DollarVolume < 50000 and x.Price > 0 and x.Price <= 5.0] #for x in myuniverse: #self.Debug('stock: ' + str(x.Symbol.Value) #+ ', price: ' + str(x.Price) + ', adjustedprice: ' + str(x.AdjustedPrice)) stocks = {x.Symbol: x for x in myuniverse} self.coarseclose.clear() #self.yesterdayclose = {} for c in myuniverse: self.coarseclose[c.Symbol] = c.AdjustedPrice ''' histStocks=list(stocks.keys()) history = self.History(histStocks, self.coursedays, Resolution.Daily) dollarvolumes = {} stddev={} prices={} for stock in histStocks: if stock in history.index: df = history.loc[stock].dropna() if df.empty or len(df)<self.coursedays: continue dollarvolumes[stock] = (df["close"]*df["volume"]).mean() stddev[stock]=((df["close"].pct_change()).std())*15.87*100 mystocks = {x: x for x in stddev if stddev[x] < 10 } mystocks4= {k:v for (k,v) in stddev.items() if v <10} mystocks1 = {x: x for x in stddev if stddev[x] < 50 } mystocks2 = {x: x for x in stddev if stddev[x] < 100 } mystocks3 = {x: x for x in stddev if stddev[x] < 5 } return list(mystocks.keys()) ''' return list(stocks.keys()) def SelectFine(self,fine): ''' This function takes the stock of the CoarceFundamental function and narrow the list adding specific fundamental filters ''' fine_filter = [x.Symbol for x in fine if x.SecurityReference.IsPrimaryShare == 1 and x.SecurityReference.SecurityType == 'ST00000001' and x.CompanyReference.IsLimitedPartnership == 0 and x.SecurityReference.IsDepositaryReceipt == 0 ] self.fineclose.clear() self.traded.clear() self.fineclose = {k: self.coarseclose[k] for k in fine_filter} self.traded = {k: 0 for k in fine_filter} return fine_filter 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 ''' for kvp in data.Bars: symbol = kvp.Key close = kvp.Value.Close dollarvolume=kvp.Value.Close*kvp.Value.Volume target =self.fineclose[kvp.Key]*self.targetentry if self.Portfolio[symbol].Quantity == 0.0: if self.traded[symbol] == 0: if close>=target: if self.Time.hour <= 15 and self.Time.minute <=29: if dollarvolume >= 10000: self.traded[symbol]=1 #self.SetHoldings(symbol, (min(1/len(self.traded),0.01))) self.SetHoldings(symbol,0.01 ) if self.Portfolio[symbol].Invested: cost = round(self.Portfolio[symbol].AveragePrice,3) profittarget = cost * 1.30 stoploss = cost * 0.9 if self.Time.hour <= 15 and self.Time.minute <=29: if (close >= profittarget) or (close <= stoploss): self.Liquidate() #self.Log("OnData(Slice): {0}: {1}: {2}".format(self.Time, symbol, value.Close)) def ClosePositions(self): if self.Portfolio.Invested: self.Liquidate()