Overall Statistics
Total Trades
600
Average Win
0.49%
Average Loss
-0.04%
Compounding Annual Return
29.717%
Drawdown
33.600%
Expectancy
9.686
Net Profit
268.050%
Sharpe Ratio
1.035
Probabilistic Sharpe Ratio
43.039%
Loss Rate
18%
Win Rate
82%
Profit-Loss Ratio
12.03
Alpha
0.099
Beta
1.206
Annual Standard Deviation
0.219
Annual Variance
0.048
Information Ratio
1.287
Tracking Error
0.094
Treynor Ratio
0.188
Total Fees
$607.00
Estimated Strategy Capacity
$240000000.00
Lowest Capacity Asset
CVS R735QTJ8XC9X
# Top Dollar Volume Top EMAR universe

from AlgorithmImports import *

# --------------------------------------------------------
N_DV = 20;  N_MOM = 10; FAST = 50; SLOW = 200; LEV = 1.00; 
# --------------------------------------------------------
class DollarVolumeEmacUniverse(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2017, 6, 1)
        self.SetEndDate(2022, 6, 2)
        self.SetCash(100000)
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.CoarseSelectionFunction)       
        self.dollar_volume_top = []        
        self.ema_f = {}
        self.ema_s = {}
        self.emar = {}
        self.universeMonth = -1
        self.SetWarmUp(5*SLOW, Resolution.Daily)
    
    
    def CoarseSelectionFunction(self, universe):
        if self.Time.month == self.universeMonth:
            return self.dollar_volume_top
        stocks = [x for x in universe if (x.HasFundamentalData)]
        price_above_10 =  [x for x in stocks if (x.Price > 10)]
        dollar_volume = sorted(price_above_10, key = lambda c: c.DollarVolume, reverse=True)
        self.dollar_volume_top = [c.Symbol for c in dollar_volume[:N_DV]]        
                    
        return self.dollar_volume_top

       
    def OnSecuritiesChanged(self, changes):  
        for x in changes.RemovedSecurities:
            if x.Symbol in self.dollar_volume_top:
                del self.dollar_volume_top[x.Symbol] 
        for symbol in self.dollar_volume_top:
            self.ema_f[symbol] = self.EMA(symbol, FAST, Resolution.Daily)
            self.ema_s[symbol] = self.EMA(symbol, SLOW, Resolution.Daily)

     
    def OnData(self, data):  
        if self.IsWarmingUp: return
        if self.Time.month == self.universeMonth: return

        self.selectedSymbols = []        
        
        for symbol in self.dollar_volume_top:
            self.emar[symbol] = self.ema_f[symbol].Current.Value / self.ema_s[symbol].Current.Value if  self.ema_s[symbol].Current.Value > 0 else 1.0
        self.selectedSymbols = sorted(self.emar, key = lambda x: self.emar[x])[:N_MOM] 
        self.Plot("Universe", "top_dv_top_emar_symbols", len(self.selectedSymbols))  

        for symbol in self.Portfolio.Keys:
            if symbol not in self.selectedSymbols:
                self.Liquidate(symbol)
                    
        for symbol in self.selectedSymbols:          
            wt = LEV/len(self.selectedSymbols) if len(self.selectedSymbols) > 0 else 0
            self.SetHoldings(symbol, wt)         

        self.universeMonth = self.Time.month