Overall Statistics |
Total Trades 794 Average Win 4.56% Average Loss -0.58% Compounding Annual Return -79.126% Drawdown 67.200% Expectancy -0.157 Net Profit -48.283% Sharpe Ratio -0.53 Probabilistic Sharpe Ratio 6.494% Loss Rate 90% Win Rate 10% Profit-Loss Ratio 7.81 Alpha -0.261 Beta 2.654 Annual Standard Deviation 0.863 Annual Variance 0.744 Information Ratio -0.483 Tracking Error 0.794 Treynor Ratio -0.172 Total Fees $3970.00 Estimated Strategy Capacity $2800000.00 Lowest Capacity Asset TQQQ 2T |
#region imports from AlgorithmImports import * #endregion class CasualRedOrangeGull(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 11, 18) self.SetEndDate(2022, 4, 20) self.SetCash(120000) self.symbol = "TQQQ" self.quantity = 1000 self.SPY = self.AddEquity(self.symbol, Resolution.Minute) self.SQQQ = self.AddEquity("SQQQ", Resolution.Minute) self.SetWarmUp(252) self.max = self.MAX(self.symbol, 390) self.min = self.MIN(self.symbol, 390) #self.Log(f'called initialize') self.pasthigh = {} self.pastlow = {} self.dayuptrend = 1 self.daydowntrend = 0 self.stoporderflag = 0 self.stopprice = 0.0 self.stoplossfactor = 1 self.short = 0 self.dayopen = 0 def OnWarmupFinished(self): self.MarketOrder(self.symbol, self.quantity) def OnData(self, data): if not (self.max.IsReady and self.min.IsReady): #self.Log("no warmup, return") return reftime = datetime(self.Time.year,self.Time.month,self.Time.day,16,0) self.pasthigh[reftime]=self.max.Current.Value self.pastlow[reftime]=self.min.Current.Value onedaysago = reftime - timedelta(days=1) twodaysago = reftime - timedelta(days=2) threedaysago = reftime - timedelta(days=3) fourdaysago = reftime - timedelta(days=4) fivedaysago = reftime - timedelta(days=5) sixdaysago = reftime - timedelta(days=6) if (onedaysago) in self.pasthigh : #self.Log(f'onedaysago Key exists 1 days') onedaysago = onedaysago elif (twodaysago) in self.pasthigh : #self.Log(f'onedaysago Key exists 2 days') onedaysago = twodaysago elif (threedaysago) in self.pasthigh : #self.Log(f'onedaysago Key exists 3 days') onedaysago = threedaysago elif (fourdaysago) in self.pasthigh: #self.Log(f'onedaysago Key exists 4 days') onedaysago = fourdaysago elif (fivedaysago) in self.pasthigh: #self.Log(f'onedaysago Key exists 5 days') onedaysago = fivedaysago elif (sixdaysago) in self.pasthigh: #self.Log(f'onedaysago Key exists 6 days') onedaysago = sixdaysago if (twodaysago) in self.pasthigh and twodaysago < onedaysago: #self.Log(f'twodaysago Key exists 2 days') twodaysago = twodaysago elif (threedaysago) in self.pasthigh and threedaysago < onedaysago: #self.Log(f'twodaysago Key exists 3 days') twodaysago = threedaysago elif (fourdaysago) in self.pasthigh and fourdaysago < onedaysago: #self.Log(f'twodaysago Key exists 4 days') twodaysago = fourdaysago elif (fivedaysago) in self.pasthigh and fivedaysago < onedaysago: #self.Log(f'twodaysago Key exists 5 days') twodaysago = fivedaysago elif (sixdaysago) in self.pasthigh and sixdaysago < onedaysago: #self.Log(f'twodaysago Key exists 6 days') twodaysago = sixdaysago # if (reftime == datetime(2021,1,6,16,0)): # self.pasthigh[onedaysago]=372.5 # self.pastlow[onedaysago]=368.05 # self.pasthigh[twodaysago]=375.45 # self.pastlow[twodaysago]=364.82 if (self.Portfolio[self.symbol].Invested ) and self.stopprice == 0.0 and (onedaysago) in self.pasthigh: self.stoporderflag = 1 self.stopprice = self.stoplossfactor * self.pasthigh[onedaysago] #self.Log(f'stopprice 0.0 set: {self.Time}') if (onedaysago in self.pasthigh): self.stopprice = self.stoplossfactor * self.pasthigh[onedaysago] # if (self.Time.hour == 16) and (self.Time.minute == 0) : # self.Log(f'High: {self.max.Current.Value}, Low: {self.min.Current.Value}, DayHigh: {data[self.symbol].High}, Time {self.Time} ') # self.Log(f'pasthigh: {self.pasthigh}') # self.Log(f'pastlow: {self.pastlow}') # if (self.Time.hour == 15) and (self.Time.minute == 59) : # if (twodaysago) in self.pasthigh : # if (self.Portfolio[self.symbol].Invested ) : # if (data[self.symbol].Close < self.pasthigh[twodaysago]) : # self.MarketOrder(self.symbol, -self.quantity) # #self.Log(f'invested, selling') # self.stoporderflag = 0 # else: # self.Log(f'Key does not exist while selling 1') # if (self.Time.hour == 9) and (self.Time.minute == 31) : # if (twodaysago) in self.pasthigh : # if (self.Portfolio[self.symbol].Invested ) : # if (data[self.symbol].Open < self.pasthigh[twodaysago]) : # self.MarketOrder(self.symbol, -self.quantity) # self.Log(f'invested, selling') # self.daydowntrend = 1 # else: # self.Log(f'Key does not exist while selling 2') if (self.Time.hour == 9) and (self.Time.minute == 31) : ##if (self.Time.hour <= 15) and (self.Time.minute <= 59) : self.dayopen = data[self.symbol].Open if (onedaysago) in self.pasthigh : if not (self.Portfolio[self.symbol].Invested ): if (data[self.symbol].Open > self.pastlow[onedaysago]) : self.MarketOrder(self.symbol, self.quantity) #self.MarketOrder("SQQQ", -self.quantity) #self.Log(f'not invested, buying') #self.StopMarketOrder(self.symbol, -self.quantity, 0.9 * data[self.symbol].Open) self.stoporderflag = 1 #self.stopprice = self.stoplossfactor * data[self.symbol].Open else: self.Log(f'Key does not exist while buying') if (self.Time.hour == 13) and (self.Time.minute == 0) : if (onedaysago) in self.pasthigh : if not (self.Portfolio[self.symbol].Invested ): if (data[self.symbol].Open > self.pastlow[onedaysago]) : self.MarketOrder(self.symbol, self.quantity) #self.MarketOrder("SQQQ", -self.quantity) #self.Log(f'not invested, buying') #self.StopMarketOrder(self.symbol, -self.quantity, 0.9 * data[self.symbol].Open) self.stoporderflag = 1 #self.stopprice = self.stoplossfactor * data[self.symbol].Open else: self.Log(f'Key does not exist while buying2') #if (self.Time.hour == 15) and (self.Time.minute == 59) : # self.Log(f'1559') #if (self.stoporderflag == 1) : #if (self.Time.hour == 15) and (self.Time.minute == 59) : if (self.Portfolio[self.symbol].Invested ) : if (data.ContainsKey(self.symbol)) and (data[self.symbol].Close < self.dayopen) and (data[self.symbol].Close < self.stopprice) : self.MarketOrder(self.symbol, -self.quantity) #self.Log(f'invested, selling stop loss') self.stoporderflag = 0 #self.MarketOrder("SQQQ", self.quantity) else: if (data.ContainsKey(self.symbol)) and (data[self.symbol].Close > self.dayopen) : self.MarketOrder(self.symbol, self.quantity) #self.Log(f'not invested, buying') self.stoporderflag = 1 #if (self.Time.hour == 15) and (self.Time.minute == 59) :
#region imports from AlgorithmImports import * #endregion class EMAMomentumUniverse(QCAlgorithm): # Order ticket for our stop order, Datetime when stop order was last hit stopMarketTicket = None stopMarketOrderFillTime = datetime.min highestSPYPrice = -1 sym = 'GME' def Initialize(self): self.SetStartDate(2020, 12, 1) self.SetEndDate(2021, 3, 8) self.SetCash(100000) spy = self.AddEquity(self.sym, Resolution.Daily) spy.SetDataNormalizationMode(DataNormalizationMode.Raw) def OnData(self, data): # 1. Plot the current SPY price to "Data Chart" on series "Asset Price" self.Plot("Data Chart", "Asset Price", data[self.sym].Close) if (self.Time - self.stopMarketOrderFillTime).days < 1: return if not self.Portfolio.Invested: self.MarketOrder(self.sym, 10) self.stopMarketTicket = self.StopMarketOrder(self.sym, -10, 0.9 * self.Securities[self.sym].Close) else: #2. Plot the moving stop price on "Data Chart" with "Stop Price" series name self.Plot("Data Chart", "Stop Price", self.stopMarketTicket.Get(OrderField.StopPrice)) if self.Securities[self.sym].Close > self.highestSPYPrice: self.highestSPYPrice = self.Securities[self.sym].Close updateFields = UpdateOrderFields() updateFields.StopPrice = self.highestSPYPrice * 0.9 self.stopMarketTicket.Update(updateFields) def OnOrderEvent(self, orderEvent): if orderEvent.Status != OrderStatus.Filled: return if self.stopMarketTicket is not None and self.stopMarketTicket.OrderId == orderEvent.OrderId: self.stopMarketOrderFillTime = self.Time