Overall Statistics |
Total Trades 4782 Average Win 0.14% Average Loss -1.00% Compounding Annual Return 39.142% Drawdown 25.500% Expectancy 0.109 Net Profit 83.153% Sharpe Ratio 1.034 Probabilistic Sharpe Ratio 43.415% Loss Rate 3% Win Rate 97% Profit-Loss Ratio 0.14 Alpha 0.223 Beta 1.283 Annual Standard Deviation 0.306 Annual Variance 0.094 Information Ratio 1.005 Tracking Error 0.243 Treynor Ratio 0.247 Total Fees $6732.00 Estimated Strategy Capacity $11000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
#region imports from AlgorithmImports import * #endregion class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2020,9,7) self.SetCash(2000000) self.Data_Symbol = {} tickers = ["SPY", #10 stocks per row "AAPL","MSFT","AMZN","GOOGL", "FB", "TSLA", "TSM", "BABA","V", ] #self.SetWarmUp(10, Resolution.Daily) for stock in tickers: symbol = self.AddEquity(stock, Resolution.Minute).Symbol self.Data_Symbol[symbol] = SymbolData(self, symbol) self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.Every(timedelta(minutes=1)), self.EveryDayAfterMarketOpen) def EveryDayAfterMarketOpen(self): #if self.IsWarmingUp: return for symbol, symbol_data in self.Data_Symbol.items(): if not symbol_data.cci.IsReady: continue holdings = self.Portfolio[symbol] invested = holdings.Invested nowprice = holdings.Price aveprice = holdings.AveragePrice quantity = holdings.Quantity bpower = self.Portfolio.Cash vestedvalue = self.Portfolio.TotalHoldingsValue totalvalue = self.Portfolio.TotalPortfolioValue limita = 0.1 * totalvalue mofactor = 100 losta = 0.98 pofita = 1.03 dropa = 0.95 cci = symbol_data.cci.Current.Value ccil = symbol_data.ccil.Current.Value rsi = symbol_data.rsi.Current.Value wilr = symbol_data.wilr.Current.Value close = symbol_data.close.Current.Value opena = symbol_data.open.Current.Value high = symbol_data.high.Current.Value if self.LiveMode and not invested: # and bpower > nowprice * mofactor and nowprice < limita and vestedvalue < (0.7 * totalvalue): self.Log(f'{symbol} :: {cci:.6},{ccil:.6},{rsi:.6},{wilr:.6},{close:.6},{opena:.6},{high:.6}') if self.LiveMode and invested and quantity > 0 and ((bpower > nowprice * mofactor and nowprice < aveprice * 0.95) or nowprice > aveprice * pofita): self.Log(f'{symbol} :: {aveprice:.6}, {nowprice:.6},{quantity:.6},{bpower:.6}') #Halt due to day trade limit### if not invested and vestedvalue < (0.7 * totalvalue) and bpower > nowprice * mofactor and (nowprice * mofactor) < limita: if (nowprice < close * losta) or (nowprice < opena * losta) or (nowprice < high * dropa) or cci < -50 or ccil < -90 or rsi < 20 or wilr < -85: self.MarketOrder(symbol, mofactor) if self.LiveMode: self.Log(f'{symbol} bought on {self.Time}') if invested and nowprice < aveprice * 0.95 and bpower > nowprice * mofactor and quantity < (6 * mofactor): #self.MarketOrder(symbol, + mofactor) self.LimitOrder(symbol, + mofactor, (aveprice * 0.95)) if invested and nowprice < aveprice * 0.90 and bpower > nowprice * mofactor and quantity > (4 * mofactor) and quantity < (10 * mofactor): #self.MarketOrder(symbol, + mofactor) self.LimitOrder(symbol, + mofactor, (aveprice * 0.90)) if invested and nowprice > aveprice * pofita: self.LimitOrder(symbol, (-1 * quantity), (aveprice * pofita)) if invested and nowprice < aveprice * 0.85: self.Liquidate(symbol) class SymbolData: def __init__ (self,algo,symbol): self.algorithm = algo self.symbol = symbol self.cci = algo.CCI(symbol, 3, MovingAverageType.Simple, Resolution.Hour) self.ccil = algo.CCI(symbol, 5, MovingAverageType.Simple, Resolution.Hour) self.rsi = algo.RSI(symbol, 5, MovingAverageType.Simple, Resolution.Hour) self.wilr = algo.WILR(symbol, 5, Resolution.Hour) self.close = algo.Identity(symbol, Resolution.Daily,Field.Close) self.open = algo.Identity(symbol, Resolution.Hour,Field.Open) self.high = algo.Identity(symbol, Resolution.Hour,Field.High)