Overall Statistics
Total Trades
8
Average Win
0%
Average Loss
0%
Compounding Annual Return
42.589%
Drawdown
3.200%
Expectancy
0
Net Profit
6.933%
Sharpe Ratio
3.433
Probabilistic Sharpe Ratio
83.431%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.286
Beta
0.138
Annual Standard Deviation
0.102
Annual Variance
0.011
Information Ratio
-1.001
Tracking Error
0.13
Treynor Ratio
2.556
Total Fees
$11.05
class LiquidUniverseSelection(QCAlgorithm):
    
    filteredByPrice = None
    
    def Initialize(self):
        self.SetStartDate(2019, 1, 11)  
        self.SetEndDate(2019, 3, 20) 
        self.SetCash(100000)  
        
        self.stateData = { }
        
        self.AddUniverse(self.CoarseSelectionFilter)
        # Ignore this for now, we'll cover it in the next task.
        self.UniverseSettings.Resolution = Resolution.Daily 

    def CoarseSelectionFilter(self, coarse):
        
        
        sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) 
        filteredByPrice = [x for x in sortedByDollarVolume if x.Price > 1 and x.Price < 100]
        
        for c in filteredByPrice:
            if c.Symbol not in self.stateData:
                self.stateData[c.Symbol] = SelectionData(c.Symbol, 10)
                
            avg = self.stateData[c.Symbol]
            avg.update(c.EndTime, c.AdjustedPrice, c.DollarVolume)
            
            
        self.values = [symbol for symbol, sd in self.stateData.items() if sd.sma.Current.Value > 3500000]
        
        return self.values[:8]
   
    def OnSecuritiesChanged(self, changes):
        #self.changes = changes
        #self.Log(f"OnSecuritiesChanged({self.UtcTime}):: {changes}")
        
        #1. Liquidate removed securities
        #for security in changes.RemovedSecurities:
        #    if security.Invested:
        #        self.Liquidate(security.Symbol)
                
        #2. We want 10% allocation in each security in our universe
        for security in changes.AddedSecurities:
            self.SetHoldings(security.Symbol, 0.1)
   
class SelectionData(object):
    def __init__(self, symbol, period):
        self.symbol = symbol
        self.volume = 0
        self.sma = SimpleMovingAverage(period)
        #self.vol_greater = False

    def update(self, time, price, volume):
        self.volume = volume
        self.sma.Update(time, volume)
            #self.vol_greater = self.sma > 3500000