from AlgorithmImports import *

class AssetGrowth(QCAlgorithm):


 

    def Initialize(self):

        #rebalancing should occur in July

        self.SetStartDate(2008,6,15)  #Set Start Date

        self.SetEndDate(2010,7,15)    #Set End Date

        self.SetCash(1000000)           #Set Strategy Cash

        self.UniverseSettings.Resolution = Resolution.Daily

        self.previous_fine = None

        self.filtered_fine = None

        self.AddUniverse(self.CoarseSelectionFunction,self.FineSelectionFunction)

        self.AddEquity("SPY", Resolution.Daily)

        #monthly scheduled event but will only rebalance once a year

        self.Schedule.On(self.DateRules.WeekStart("SPY"), self.TimeRules.At(10, 0), self.rebalance)

        self.months = -1

        self.yearly_rebalance = False

        self.SetAlpha(ConstantAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(30)))

        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(lambda time:None))

        self.current_month = -1

        self.coarse_count = 300

        self.fine_count = 10

       

    def CoarseSelectionFunction(self, coarse):

        if self.yearly_rebalance:

            # drop stocks which have no fundamental data

            #filtered_coarse = [x.Symbol for x in coarse if (x.HasFundamentalData) and (x.Market == "usa")]

            filtered_coarse = [x.Symbol for x in coarse]

            self.Debug("CoarseSelectionFunction")

            self.Debug(filtered_coarse)

            sortedByDollarVolume = sorted([x for x in coarse if (x.HasFundamentalData)],

                key=lambda x: x.DollarVolume, reverse=True)[:self.coarse_count]

            filtered_coarse = [i.Symbol for i in sortedByDollarVolume]

            self.Debug(filtered_coarse)

            return filtered_coarse

        else:

            return []

 

terminal  output:

4667

 

|

10:36:28

:

CoarseSelectionFunction

4668

 

|

10:36:28

:

[, , , ,

4669

 

|

10:36:28

:

[, , , ,

 

i  am  confused ,how  can  i  get   stock  symbol  for   all   US  stock?