Overall Statistics |
Total Trades 5 Average Win 0% Average Loss 0% Compounding Annual Return -26.984% Drawdown 26.600% Expectancy 0 Net Profit -19.069% Sharpe Ratio -0.573 Probabilistic Sharpe Ratio 5.438% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.001 Beta 1.239 Annual Standard Deviation 0.284 Annual Variance 0.081 Information Ratio -0.23 Tracking Error 0.14 Treynor Ratio -0.131 Total Fees $5.00 Estimated Strategy Capacity $65000000.00 Lowest Capacity Asset BABA VU1EHIDJYJXH |
#region imports from AlgorithmImports import * #endregion class RetrospectiveBlueSeahorse(QCAlgorithm): def Initialize(self): # # # # # User input area # # # # # # Set start date self.SetStartDate(2022, 1, 13) # Strategy cash self.SetCash(100000) # User input list of stocks list_of_stocks = ["AMZN","AAPL","TSLA","BABA","AMD"] # # # # # End user input area # # # # # # Rolling RSI dictionary self.rolling_rsi_dictionary = {} # MACD dictionary self.macd_dictionary = {} # RSI dictionary self.rsi_dictionary = {} # SMA 14-period dictionary self.sma_forteen_dictionary = {} # SMA 26-period dictionary self.sma_twentysix_dictionary = {} # SMA 30-period dictionary self.sma_thirty_dictionary = {} # Yesterday close dictionary self.yesterday_close = {} # Symbol list symbol_list = [] # Loop through stocks for ticker in list_of_stocks: # Initialize stock symbol = self.AddEquity(ticker, Resolution.Minute).Symbol # Add to symbol list symbol_list.append(symbol) # Minute history call history = self.History(symbol_list, 100, Resolution.Minute) # Daily history call daily_history = self.History(symbol_list, 1, Resolution.Daily) # Loop through added symbols for symbol in symbol_list: # Initialize security in rolling RSI dictionary self.rolling_rsi_dictionary[symbol] = [] # MACD dictionary self.macd_dictionary[symbol] = self.MACD(symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute) # RSI dictionary self.rsi_dictionary[symbol] = self.RSI(symbol, 14, MovingAverageType.Simple, Resolution.Minute) # SMA 14-period dictionary self.sma_forteen_dictionary[symbol] = self.SMA(symbol, 14, Resolution.Minute) # SMA 26-period dictionary self.sma_twentysix_dictionary[symbol] = self.SMA(symbol, 26, Resolution.Minute) # SMA 30-period dictionary self.sma_thirty_dictionary[symbol] = self.SMA(symbol, 30, Resolution.Minute) # # Yesterday close dictionary self.yesterday_close[symbol] = daily_history.loc[symbol]["close"][-1] # Loc history data for asset asset_history = history.loc[symbol] # Loop through history of asset for time, row in asset_history.iterrows(): # Update macd indicator of asset self.macd_dictionary[symbol].Update(time, row.close) # Update rsi indicator for asset self.rsi_dictionary[symbol].Update(time, row.close) # Update SMA 14-period for asset self.sma_forteen_dictionary[symbol].Update(time, row.close) # Update SMA 26-period for asset self.sma_twentysix_dictionary[symbol].Update(time, row.close) # Update SMA 26-period for asset self.sma_thirty_dictionary[symbol].Update(time, row.close) # Add SPY to schedule events self.AddEquity("SPY", Resolution.Minute) # Schedule saving of market closing price self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 0), self.save_market_closing) # Save market closing price function def save_market_closing(self): # Loop through all assets for symbol in self.yesterday_close: # Update close price self.yesterday_close[symbol] = self.Securities[symbol].Close def OnData(self, data): # # # # # Long position logic # # # # # # Loop through all assets for symbol in self.rolling_rsi_dictionary: # Update rolling RSI self.rolling_rsi_dictionary[symbol].append(self.rsi_dictionary[symbol].Current.Value) # Check if length of rolling RSI dictionary is greater than 60 if len(self.rolling_rsi_dictionary[symbol]) > 60: # Cut length self.rolling_rsi_dictionary[symbol] = self.rolling_rsi_dictionary[symbol][-60:] # Check if MACD is greater than MACD signal if self.macd_dictionary[symbol].Current.Value > self.macd_dictionary[symbol].Signal.Current.Value: # Check if RSI is greater than its value 1 hour ago if self.rsi_dictionary[symbol].Current.Value > self.rolling_rsi_dictionary[symbol][-60]: # Check if 14-period SMA is greater than 30-period SMA if self.sma_forteen_dictionary[symbol].Current.Value > self.sma_thirty_dictionary[symbol].Current.Value: # Check if current close greater than yesterday close if self.Securities[symbol].Close > self.yesterday_close[symbol]: # If not invested if not self.Portfolio[symbol].Invested: # Get cash available cash = self.Portfolio.Cash # Get 25% of cash available cash_allocation = cash * 0.25 # Calculate quantity quantity = int(cash_allocation / self.Securities[symbol].Close) # Submit market order self.MarketOrder(symbol, quantity) # # # # # Liquidation logic # # # # # # Get holdings holdings = [x.Key for x in self.Portfolio if x.Value.Invested] # Loop through holdings for symbol in holdings: # If current MACD < MACD signal if self.macd_dictionary[symbol].Current.Value < self.macd_dictionary[symbol].Signal.Current.Value: # If RSI is less than its value 1 hour ago if self.rsi_dictionary[symbol].Current.Value < self.rolling_rsi_dictionary[symbol][-1]: # If 26-period SMA less than most recent close price if self.sma_twentysix_dictionary[symbol].Current.Value < self.Securities[symbol].Close: # Close position with market order self.MarketOrder(symbol, -self.Portfolio[symbol].Quantity)
#region imports from AlgorithmImports import * #endregion class RetrospectiveBlueSeahorse(QCAlgorithm): def Initialize(self): # # # # # User input area # # # # # # Set start date self.SetStartDate(2022, 1, 13) # Strategy cash self.SetCash(25000) # User input list of stocks # # # Tickers need to be in capital letters # # # list_of_stocks = ["AMZN","AAPL","TSLA","BABA","AMD","BP","F","GME","AMC"] # # # # # End user input area # # # # # # Rolling RSI dictionary self.rolling_rsi_dictionary = {} # MACD dictionary self.macd_dictionary = {} # RSI 6-minute dictionary self.rsi_six_minute_dictionary = {} # RSI 14-minute dictionary self.rsi_forteen_minute_dictionary = {} # SMA 14-period dictionary self.sma_forteen_dictionary = {} # SMA 26-period dictionary self.sma_twentysix_dictionary = {} # SMA 30-period dictionary self.sma_thirty_dictionary = {} # Yesterday close dictionary self.yesterday_close = {} # Symbol list symbol_list = [] # Loop through stocks for ticker in list_of_stocks: # Initialize stock # # # QuantConnect supports tick, second, minute, hour and daily resolution # # # symbol = self.AddEquity(ticker, Resolution.Minute, "USA", True, 0, False).Symbol # Add to symbol list symbol_list.append(symbol) # Minute history call # # # The first parameter has to be a list # # # history = self.History(symbol_list, 100, Resolution.Minute) # Daily history call daily_history = self.History(symbol_list, 1, Resolution.Daily) # Loop through added symbols for symbol in symbol_list: # Initialize security in rolling RSI dictionary self.rolling_rsi_dictionary[symbol] = [] # MACD dictionary self.macd_dictionary[symbol] = self.MACD(symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute, Field.Open) # 6-minute RSI dictionary self.rsi_six_minute_dictionary[symbol] = self.RSI(symbol, 6, MovingAverageType.Simple, Resolution.Minute) # 14-minute RSI dictionary self.rsi_forteen_minute_dictionary[symbol] = self.RSI(symbol, 14, MovingAverageType.Simple, Resolution.Minute) # SMA 14-period dictionary self.sma_forteen_dictionary[symbol] = self.SMA(symbol, 14, Resolution.Minute) # SMA 26-period dictionary self.sma_twentysix_dictionary[symbol] = self.SMA(symbol, 26, Resolution.Minute) # SMA 30-period dictionary self.sma_thirty_dictionary[symbol] = self.SMA(symbol, 30, Resolution.Minute) # # Yesterday close dictionary self.yesterday_close[symbol] = daily_history.loc[symbol]["close"][-1] # Loc history data for asset asset_history = history.loc[symbol] # Loop through history of asset for time, row in asset_history.iterrows(): # Update macd indicator of asset self.macd_dictionary[symbol].Update(time, row.open) # Update 6-minute rsi indicator for asset self.rsi_six_minute_dictionary[symbol][symbol].Update(time, row.close) # Update 14-minute rsi indicator for asset self.rsi_forteen_minute_dictionary[symbol][symbol].Update(time, row.close) # Update SMA 14-period for asset self.sma_forteen_dictionary[symbol].Update(time, row.close) # Update SMA 26-period for asset self.sma_twentysix_dictionary[symbol].Update(time, row.close) # Update SMA 26-period for asset self.sma_thirty_dictionary[symbol].Update(time, row.close) # Add SPY to schedule events self.AddEquity("SPY", Resolution.Minute) # Schedule saving of market closing price self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 0), self.save_market_closing) # Save market closing price function def save_market_closing(self): # Loop through all assets for symbol in self.yesterday_close: # Update close price self.yesterday_close[symbol] = self.Securities[symbol].Close def OnData(self, data): # # # # # Long position logic # # # # # # Loop through all assets for symbol in self.macd_dictionary: # Check if MACD is greater than MACD signal if self.macd_dictionary[symbol].Current.Value > self.macd_dictionary[symbol].Signal.Current.Value: # Check if 14-period SMA is greater than 30-period SMA if self.sma_forteen_dictionary[symbol].Current.Value > self.sma_thirty_dictionary[symbol].Current.Value: # Check if current close greater than yesterday close if self.Securities[symbol].Close > self.yesterday_close[symbol]: # If not invested if not self.Portfolio[symbol].Invested: # Get cash available cash = self.Portfolio.Cash # Get 25% of cash available cash_allocation = cash * 0.25 # Calculate quantity quantity = int(cash_allocation / self.Securities[symbol].Close) # If quantity is greater than 1 if quantity > 1: # Send SMS to Yomi's phone number self.Notify.Sms("+1234567890", "Buy signal for " + symbol.Value + " triggered") # Submit market order self.MarketOrder(symbol, quantity) # # # # # Liquidation logic # # # # # # Get holdings holdings = [x.Key for x in self.Portfolio if x.Value.Invested] # Loop through holdings for symbol in holdings: # If current MACD < MACD signal if self.macd_dictionary[symbol].Current.Value < self.macd_dictionary[symbol].Signal.Current.Value: # If 26-period SMA less than most recent close price if self.sma_twentysix_dictionary[symbol].Current.Value < self.Securities[symbol].Close: # Send SMS to Yomi's phone number self.Notify.Sms("+1234567890", "Sell signal for " + symbol.Value + " triggered") # Close position with market order self.MarketOrder(symbol, -self.Portfolio[symbol].Quantity)
#region imports from AlgorithmImports import * #endregion class RetrospectiveBlueSeahorse(QCAlgorithm): def Initialize(self): # # # # # User input area # # # # # # Set start date self.SetStartDate(2022, 1, 13) # Strategy cash self.SetCash(100000) # User input list of stocks list_of_stocks = ["AMZN","AAPL","TSLA","BABA","AMD"] # # # # # End user input area # # # # # # Rolling RSI dictionary self.rolling_rsi_dictionary = {} # MACD dictionary self.macd_dictionary = {} # RSI dictionary self.rsi_dictionary = {} # SMA 14-period dictionary self.sma_forteen_dictionary = {} # SMA 26-period dictionary self.sma_twentysix_dictionary = {} # SMA 30-period dictionary self.sma_thirty_dictionary = {} # Yesterday close dictionary self.yesterday_close = {} # Symbol list symbol_list = [] # Loop through stocks for ticker in list_of_stocks: # Initialize stock symbol = self.AddEquity(ticker, Resolution.Minute).Symbol # Add to symbol list symbol_list.append(symbol) # Minute history call history = self.History(symbol_list, 100, Resolution.Minute) # Daily history call daily_history = self.History(symbol_list, 1, Resolution.Daily) # Loop through added symbols for symbol in symbol_list: # Initialize security in rolling RSI dictionary self.rolling_rsi_dictionary[symbol] = [] # MACD dictionary self.macd_dictionary[symbol] = self.MACD(symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute) # RSI dictionary self.rsi_dictionary[symbol] = self.RSI(symbol, 14, MovingAverageType.Simple, Resolution.Minute) # SMA 14-period dictionary self.sma_forteen_dictionary[symbol] = self.SMA(symbol, 14, Resolution.Minute) # SMA 26-period dictionary self.sma_twentysix_dictionary[symbol] = self.SMA(symbol, 26, Resolution.Minute) # SMA 30-period dictionary self.sma_thirty_dictionary[symbol] = self.SMA(symbol, 30, Resolution.Minute) # # Yesterday close dictionary self.yesterday_close[symbol] = daily_history.loc[symbol]["close"][-1] # Loc history data for asset asset_history = history.loc[symbol] # Loop through history of asset for time, row in asset_history.iterrows(): # Update macd indicator of asset self.macd_dictionary[symbol].Update(time, row.close) # Update rsi indicator for asset self.rsi_dictionary[symbol].Update(time, row.close) # Update SMA 14-period for asset self.sma_forteen_dictionary[symbol].Update(time, row.close) # Update SMA 26-period for asset self.sma_twentysix_dictionary[symbol].Update(time, row.close) # Update SMA 26-period for asset self.sma_thirty_dictionary[symbol].Update(time, row.close) # Add SPY to schedule events self.AddEquity("SPY", Resolution.Minute) # Schedule saving of market closing price self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 0), self.save_market_closing) # Save market closing price function def save_market_closing(self): # Loop through all assets for symbol in self.yesterday_close: # Update close price self.yesterday_close[symbol] = self.Securities[symbol].Close def OnData(self, data): # # # # # Long position logic # # # # # # Loop through all assets for symbol in self.rolling_rsi_dictionary: # Update rolling RSI self.rolling_rsi_dictionary[symbol].append(self.rsi_dictionary[symbol].Current.Value) # Check if length of rolling RSI dictionary is greater than 60 if len(self.rolling_rsi_dictionary[symbol]) > 600: # Cut length self.rolling_rsi_dictionary[symbol] = self.rolling_rsi_dictionary[symbol][-600:] # Check if MACD is greater than MACD signal if self.macd_dictionary[symbol].Current.Value > self.macd_dictionary[symbol].Signal.Current.Value: # Check if RSI is greater than its value 1 hour ago if self.rsi_dictionary[symbol].Current.Value > self.rolling_rsi_dictionary[symbol][-600]: # Check if 14-period SMA is greater than 30-period SMA if self.sma_forteen_dictionary[symbol].Current.Value > self.sma_thirty_dictionary[symbol].Current.Value: # Check if current close greater than yesterday close if self.Securities[symbol].Close > self.yesterday_close[symbol]: # If not invested if not self.Portfolio[symbol].Invested: # Get cash available cash = self.Portfolio.Cash # Get 25% of cash available cash_allocation = cash * 0.25 # Calculate quantity quantity = int(cash_allocation / self.Securities[symbol].Close) # Submit market order self.MarketOrder(symbol, quantity) # # # # # Liquidation logic # # # # # # Get holdings holdings = [x.Key for x in self.Portfolio if x.Value.Invested] # Loop through holdings for symbol in holdings: # If current MACD < MACD signal if self.macd_dictionary[symbol].Current.Value < self.macd_dictionary[symbol].Signal.Current.Value: # If RSI is less than its value 1 hour ago if self.rsi_dictionary[symbol].Current.Value < self.rolling_rsi_dictionary[symbol][-1]: # If 26-period SMA less than most recent close price if self.sma_twentysix_dictionary[symbol].Current.Value < self.Securities[symbol].Close: # Close position with market order self.MarketOrder(symbol, -self.Portfolio[symbol].Quantity)