Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
class VerticalCalibratedRegulators(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 5, 20)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)
        self.__numberOfSymbols = 100
        self.__numberOfSymbolsFine = 5
        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)

        self.smaDictionary = {}
        self.selectedSymbols = []

    def OnData(self, data):
        pass

    # sort the data by daily dollar volume and take the top 'NumberOfSymbols'
    def CoarseSelectionFunction(self, coarse):
        # sort descending by daily dollar volume
        sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
    
        # return the symbol objects of the top entries from our sorted collection
        return [ x.Symbol for x in sortedByDollarVolume[:self.__numberOfSymbols] ]

    
    # sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
    def FineSelectionFunction(self, fine):
        # sort descending by P/E ratio
        sortedByPeRatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=True)

        ## Retrieve 20 days of historical data for each symbol
        symbols = [x.Symbol for x in sortedByPeRatio]
        history = self.History(symbols, 20, Resolution.Daily)
        ## Iterate through symbols
        for symbol in symbols:
            ## Find hsitory for specific symbol
            symbolVolumeHistory = history.loc[str(symbol)]

            ## Create SMA for symbol and register it with algorithm
            symbolSMA = SimpleMovingAverage(20)

            ## Iterate through historical data
            for tuple in symbolVolumeHistory.itertuples():
                ## Update SMA with data time and volume
                symbolSMA.Update(tuple.Index, tuple.volume)
                self.Debug(f'Updating {symbol.Value} SMA...')

            ## Add SMA to dictionary so you can access it later
            self.smaDictionary[symbol] = symbolSMA

        ## Perform SMA filtering conditions and select/return the symbols you want to add to your universe
        ## Fine Selection will use only these ones
        
        # self.selectedSymbols = ....
        # return self.selectedSymbols
        
        return symbols