Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
class UpgradedFluorescentOrangeCaterpillar(QCAlgorithm): def Initialize(self): self.SetStartDate(2022, 2, 15) # Set Start Date self.SetEndDate(2022, 2, 16) self.SetCash(100000) # Set Strategy Cash res = Resolution.Minute symbols = [ Symbol.Create("SPY", SecurityType.Equity, Market.USA) , Symbol.Create("TSLA", SecurityType.Equity, Market.USA) , Symbol.Create("HES", SecurityType.Equity, Market.USA) ] self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) ) self.tsla = self.AddEquity("TSLA",res, Market.USA, True, 0, False).Symbol self.spy = self.AddEquity("SPY", res, Market.USA, True, 0, False).Symbol self.hes = self.AddEquity("HES", res, Market.USA, True, 0, False).Symbol self.symbolDataBySymbol = {} for symbol in symbols: symbolData = self.symbolDataBySymbol.get(symbol) if symbolData is None: symbolData = SymbolData(self, symbol, 5, 2) self.symbolDataBySymbol[symbol] = symbolData else: # # a security that was already initialized was re-added, reset the indicators symbolData.RSI_MultiMin.Reset() def OnData(self, data): for symbol, symbolData in self.symbolDataBySymbol.items(): if symbolData.WasJustUpdatedMins(self.Time): if self.Time.hour == 9 and self.Time.minute >= 30 and self.Time.minute <= 35: if symbolData.Symbol == self.spy: self.Log("Start time: "+ str(symbolData.MultiMinsBar.Time) + " EndTime: " + str(str(symbolData.MultiMinsBar.EndTime) +" Bar: "+ symbolData.MultiMinsBar.ToString()+ " data Time: " +str(data.Time) )) minhistory = self.History(symbolData.Symbol, 6, Resolution.Minute).loc[symbolData.Symbol] volumeSum = minhistory.volume.sum() self.Log(minhistory) self.Log(volumeSum) def OnSecuritiesChanged(self, changes): '''Event fired each time the we add/remove securities from the data feed Args: algorithm: The algorithm instance that experienced the change in securities changes: The security additions and removals from the algorithm''' def OnEndOfAlgorithm(self): for symbol, symbolData in self.symbolDataBySymbol.items(): self.Debug( str(symbol) + " " ) class SymbolData: '''Contains data specific to a symbol required by this model''' def __init__(self, selfabove, security, ConsidMin, lookbackdays): self.Symbol = security self.ConsidMin = ConsidMin self.lookbackdays = lookbackdays self.df_min = pd.DataFrame() self.df_min = selfabove.History(self.Symbol, timedelta(days=self.lookbackdays), Resolution.Minute).loc[self.Symbol] if self.Symbol == selfabove.spy: selfabove.Log(self.df_min.head(10)) self.lengthofMinWin = self.df_min.index.size self.lengthofMultiMinWin= math.ceil(self.df_min.index.size/(self.ConsidMin)) self.rolling_windowMin = RollingWindow[TradeBar](self.lengthofMultiMinWin) self.rolling_windowMultiMin = RollingWindow[TradeBar](self.lengthofMultiMinWin) self.MultiMinsBar = None self.RSI_MultiMin = RelativeStrengthIndex(14, MovingAverageType.Simple) self.Mins = timedelta(minutes= self.ConsidMin) self.tradeBarWindowMultiMinsBar = None self.consolidatorMins = TradeBarConsolidator(self.Mins) self.consolidatorMins.DataConsolidated += self.consolidation_handler_Mins selfabove.SubscriptionManager.AddConsolidator(self.Symbol, self.consolidatorMins) selfabove.RegisterIndicator(self.Symbol, self.RSI_MultiMin, self.consolidatorMins, Field.Close) for time, row in self.df_min.iterrows(): tradebarbar = TradeBar(time, self.Symbol, row.open, row.high, row.low, row.close, row.volume) self.rolling_windowMin.Add(tradebarbar) self.consolidatorMins.Update(tradebarbar) if time.hour == 9 and time.minute >= 30 and time.minute <= 36 and self.Symbol == selfabove.spy: selfabove.Log((str( "1 min bar: " + tradebarbar.ToString())+ " start of bar: "+str(tradebarbar.Time)+" EndTime of bar: " +str(tradebarbar.EndTime))) #if time.minute == 35: # selfabove.Log((str(self.MultiMinsBar.EndTime - self.MultiMinsBar.Time) + " 5 min bar: " + self.MultiMinsBar.ToString())+" " +str(self.MultiMinsBar.EndTime)+ " "+str(time)) self.df_MultiMin = selfabove.PandasConverter.GetDataFrame[TradeBar](self.rolling_windowMultiMin) self.df_MultiMin = self.df_MultiMin.reset_index(level='symbol') self.df_MultiMin = self.df_MultiMin.drop(['symbol'], axis=1) self.df_MultiMin = self.df_MultiMin.sort_index() def consolidation_handler_Mins(self, sender, bar): self.rolling_windowMultiMin.Add(bar) self.MultiMinsBar = bar #self.Log(str(bar.EndTime - bar.Time) + " " + bar.ToString()) def WasJustUpdatedMins(self, current): return self.MultiMinsBar is not None and self.MultiMinsBar.Time == current - self.Mins