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
Probabilistic 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
-229.947
Tracking Error
0.072
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class VirtualBrownGull(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 2, 7)  # Set Start Date
        self.SetEndDate(2022, 2, 9)
        self.SetCash(100_000)
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.CoarseSelectionFunction)
        
        #self.selected = None
        
        #smavolumemin = 1000000
        #self.smavolumemin = smavolumemin
        
        self.averages = {}
    
    
    def CoarseSelectionFunction(self, coarse): # was originally self, universe
        selected = []
        
        #you do not need to sort for this algo - but maybe you wanted it for later, when more code is added
        #sortedbyPrice = sorted(coarse, key=lambda c: c.Price, reverse=True)
        filteredbyPrice = [c for c in coarse if c.Price > 2 and c.Price < 10]
        #to realize how many there are...
        self.Log(f"Number of assets: {len(filteredbyPrice)}")
        
        #you do not want to use a name already used in Python (here, a param "coarse"). The reason is too long to explain here, but be careful as this can be very nasty since Python is soooooo dynamic. Anyway.
        #for coarse in filteredbyPrice:
        for c in filteredbyPrice:
            symbol = c.Symbol
            
            if symbol not in self.averages:
                
                #many calls to history - it will take some time...
                history = self.History(symbol, 30, Resolution.Daily)
                self.averages[symbol] = SelectionData(history)
            
            self.averages[symbol].update(self.Time, c.Volume)
            
            if self.averages[symbol].is_ready():
                if self.averages[symbol].thirtysma.Current.Value > 100_000:
                    selected.append(symbol)
        
        return selected
    
    def OnSecuritiesChanged(self, changes):
        #self.Log("Hello")
        for added in changes.AddedSecurities:
            self.Log(f"stock added {added.Symbol}")
            
        for removed in changes.RemovedSecurities:
            self.Log(f"stock removed {removed.Symbol}")
        #you have nothing to return here
        #return
                
class SelectionData(): # this changes
    
    def __init__(self, history):
        self.thirtysma = SimpleMovingAverage(30)
    
        for bar in history.itertuples():
            self.thirtysma.Update(bar.Index[1], bar.volume)
    
    def is_ready(self):
        return self.thirtysma.IsReady
    
    def update(self, time, volume):
        #self.volume = volume
        self.thirtysma.Update(time, volume)