Hello,
I am facing some difficulty trying to figure coarse selection and fine selection universe. I am trying to list all stocks that trade in NYSE.
However, i am noticing that coarse seem to print approx 5K stocks however, fine always shows as an empty field. Could some one let me know what is that i am obviously doing wrong in this code?
This is what my code is:
class CoarseFineFundamentalRegressionAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019,1,3) #Set Start Date
self.SetEndDate(2019,1,4) #Set End Date
self.SetCash(50000) #Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Minute
# this add universe method accepts two parameters:
# - coarse selection function: accepts an IEnumerable<CoarseFundamental> and returns an IEnumerable<Symbol>
# - fine selection function: accepts an IEnumerable<FineFundamental> and returns an IEnumerable<Symbol>
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
self.changes = None
# return a list of three fixed symbol objects
def CoarseSelectionFunction(self, coarse):
Coarse_filtered_stocks = filter(lambda x: x.DollarVolume >0,coarse)
Coarse_filtered_stocks = filter(lambda x: x.HasFundamentalData,Coarse_filtered_stocks)
Coarse_filtered_stocks = filter(lambda x: x.Price >0,Coarse_filtered_stocks)
count = 0
for stock in Coarse_filtered_stocks:
count += 1
self.Debug(' coarse # of stocks {}'.format(count))
return [stock.symbol for stock in Coarse_filtered_stocks]
# sort the data based on what trades on NYSE
def FineSelectionFunction(self, fine):
count1 = 0
for stock in fine:
count1 += 1
self.Debug(' fine # of stocks {}'.format(count1))
filtered_fine = filter(lambda x: x.CompanyReference.PrimaryExchangeID == "NYS",fine)
return [ x.Symbol for x in filtered_fine]
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!