Hi

I am new to Quantconnect community and I am thrilled with the potential of this platform as a learning tool.

As I understood from previous descussions we don't have option to analyse volume on pre market during backtesting?

I want to know if it's possible to check most traded stocks based on volume up to 10:00 of the same day. I am reusing code from this thread but I am getting an errors for every stock in the list:

"The security does not have an accurate price as it has not yet received a bar of data.."

Can someone kindly point me to what I am doing wrong here.
My code:

class ParticleTransdimensionalAutosequencers(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 11, 26) self.SetEndDate(2020, 11, 27) self.SetCash(100000) self.AddEquity("SPY", Resolution.Minute) self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseSelectionFunction)) self.UniverseSettings.Resolution = Resolution.Minute self.Schedule.On( self.DateRules.EveryDay("SPY"), self.TimeRules.At(10, 0), self.SelectUniverse ) self.universe = [] self.volume_by_symbol = {} self.logged = False def OnData(self, data): if len(self.volume_by_symbol) == 0: if not self.logged: self.logged = True self.Log(f"Universe size after volume filter: {len(self.universe)}") return for symbol in self.volume_by_symbol.keys(): if data.ContainsKey(symbol) and data[symbol] is not None: self.volume_by_symbol[symbol] += data[symbol].Volume def CoarseSelectionFunction(self, coarse): self.volume_by_symbol = {c.Symbol: 0 for c in coarse if c.Price > 10} self.Log(f"Universe size before volume filter: {len(self.volume_by_symbol)}") return list(self.volume_by_symbol.keys()) def SelectUniverse(self): self.universe = [] for symbol, volume in self.volume_by_symbol.items(): if volume > 50000: self.universe.append(symbol) self.volume_by_symbol.clear() self.logged = False def OnSecuritiesChanged(self, changes): self.changes = changes self.Log(f"OnSecuritiesChanged({self.Time}):: {changes}") for security in self.changes.RemovedSecurities: if security.Invested: self.Liquidate(security.Symbol) for security in self.changes.AddedSecurities: self.SetHoldings(security.Symbol, 0.18) self.Debug("BUY") self.Debug(security.Symbol) self.Debug(security.Price) self.Debug(self.Time)

 

Author