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'
from AlgorithmImports import *
class DropboxCoarseFineAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 7, 7) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddUniverse(self.SelectCoarse, self.SelectFine)
self.UniverseSettings.Resolution = Resolution.Hour
self.url = "https://www.dropbox.com/s/e3w1j0hryzeprz2/tickersonly.csv?dl=1"
def SelectCoarse(self, coarse):
coarse = self.GetSymbols()
self.sortedByVolume = sorted(coarse, key=lambda x: x.Volume, reverse=True)
return [x.Symbol for x in self.sortedByVolume if x.Price > 0
and x.HasFundamentalData][:4]
def SelectFine(self, fine):
# Return symbols from our list which have a market capitalization of at least 10B
return [f.Symbol for f in fine if f.MarketCap > 1e10 and f.Symbol in symbols]
def GetSymbols(self):
self.universeData = self.Parse(self.url)
# In backtest load once if not set, then just use the dates.
if self.universeData is None:
self.universeData = self.Parse(self.url)
return self.universeData
def Parse(self, url):
# Download file from url as string
file = self.Download(url).split("\n")
# # Remove formatting characters
data = [x.replace("\r", "").replace(" ", "").replace(",", "") for x in file]
# Dictionary to hold list of active symbols for each date, keyed by date
symbolsByDate = []
# Parse data into dictionary
for arr in data:
symb = Symbol.Create(arr, SecurityType.Equity, Market.USA)
# symb = self.AddEquity(arr).Symbol
symbolsByDate.append(symb)
return symbolsByDate
def OnSecuritiesChanged(self, changes):
# self.Debug(f"Added Securities: {[security.Symbol.Value for security in changes.AddedSecurities]}")
# self.Debug(f"Removed Securities: {[security.Symbol.Value for security in changes.RemovedSecurities]}")
pass
Louis Szeto
Hi MAK K
We were unable to access the dropbox link above. Please provide another one so we can assist further.
Best,
Louis Szeto
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Mak K
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!