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(2020, 8, 20) # Set Start Date self.SetEndDate(2020, 8, 21) 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, True).Symbol self.spy = self.AddEquity("SPY", res, Market.USA, True, 0, True).Symbol self.hes = self.AddEquity("HES", res, Market.USA, True, 0, True).Symbol self.symbolDataBySymbol = {} for symbol in symbols: symbolData = self.symbolDataBySymbol.get(symbol) if symbolData is None: symbolData = SymbolData(self, symbol, 5, 10) 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 == 12 and self.Time.minute >= 55: if symbolData.Symbol == self.tsla: self.Log(str(symbolData.MultiMinsBar.EndTime - symbolData.MultiMinsBar.Time) + " " + symbolData.MultiMinsBar.ToString()+ " "+str(data.Time) ) minhistory = self.History(symbolData.Symbol, 5, Resolution.Minute).loc[symbolData.Symbol] volumeSum = minhistory.volume.sum() 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] 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) 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