Hello,

I'm unable to get stock's Volume data in a custom Coarse imported from a dropbox using a csv file.

Can anyone let me know what's wrong with the attached code ?

Error: Runtime Error: AttributeError : 'Symbol' object has no attribute 'Volume' 

  1. from AlgorithmImports import *
  2. class DropboxCoarseFineAlgorithm(QCAlgorithm):
  3. def Initialize(self):
  4. self.SetStartDate(2021, 7, 7) # Set Start Date
  5. self.SetCash(100000) # Set Strategy Cash
  6. self.AddUniverse(self.SelectCoarse, self.SelectFine)
  7. self.UniverseSettings.Resolution = Resolution.Hour
  8. self.url = "https://www.dropbox.com/s/e3w1j0hryzeprz2/tickersonly.csv?dl=1"
  9. def SelectCoarse(self, coarse):
  10. coarse = self.GetSymbols()
  11. self.sortedByVolume = sorted(coarse, key=lambda x: x.Volume, reverse=True)
  12. return [x.Symbol for x in self.sortedByVolume if x.Price > 0
  13. and x.HasFundamentalData][:4]
  14. def SelectFine(self, fine):
  15. # Return symbols from our list which have a market capitalization of at least 10B
  16. return [f.Symbol for f in fine if f.MarketCap > 1e10 and f.Symbol in symbols]
  17. def GetSymbols(self):
  18. self.universeData = self.Parse(self.url)
  19. # In backtest load once if not set, then just use the dates.
  20. if self.universeData is None:
  21. self.universeData = self.Parse(self.url)
  22. return self.universeData
  23. def Parse(self, url):
  24. # Download file from url as string
  25. file = self.Download(url).split("\n")
  26. # # Remove formatting characters
  27. data = [x.replace("\r", "").replace(" ", "").replace(",", "") for x in file]
  28. # Dictionary to hold list of active symbols for each date, keyed by date
  29. symbolsByDate = []
  30. # Parse data into dictionary
  31. for arr in data:
  32. symb = Symbol.Create(arr, SecurityType.Equity, Market.USA)
  33. # symb = self.AddEquity(arr).Symbol
  34. symbolsByDate.append(symb)
  35. return symbolsByDate
  36. def OnSecuritiesChanged(self, changes):
  37. # self.Debug(f"Added Securities: {[security.Symbol.Value for security in changes.AddedSecurities]}")
  38. # self.Debug(f"Removed Securities: {[security.Symbol.Value for security in changes.RemovedSecurities]}")
  39. pass
+ Expand

 

Author

Mak K

July 2021