Overall Statistics
Total Trades
237
Average Win
2.84%
Average Loss
-2.22%
Compounding Annual Return
28.003%
Drawdown
50.500%
Expectancy
0.160
Net Profit
13.250%
Sharpe Ratio
0.945
Probabilistic Sharpe Ratio
40.125%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.28
Alpha
1.103
Beta
-0.781
Annual Standard Deviation
0.925
Annual Variance
0.856
Information Ratio
0.616
Tracking Error
0.944
Treynor Ratio
-1.119
Total Fees
$1131.12
Estimated Strategy Capacity
$430000.00
Lowest Capacity Asset
NE R735QTJ8XC9X

class PensiveBlackSalamander(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 28)
        self.SetCash(100000) 
        self.AddUniverse(self.MyCoarseFilterFunction)
        self.selected = []
        self.UniverseSettings.Resolution = Resolution.Daily
        self.dataBySymbol = {}
        self.AddEquity("SPY")
        self.Schedule.On(self.DateRules.MonthStart("SPY"), \
                 self.TimeRules.AfterMarketOpen("SPY"), \
                 self.liquidate)
    def liquidate(self):
        self.Liquidate()
        

    def MyCoarseFilterFunction(self, coarse):
         
         
         
         filtered = [ x for x in coarse 
                      if x.Price > 10 and x.DollarVolume > 10000000 ]
        # probably want some different logic for filtered or none at all
#         filtered = filtered[:20]
         
         self.selected = []
         
         for x in filtered:
             if x.Symbol not in self.dataBySymbol:
                 self.dataBySymbol[x.Symbol] = SymbolData(self,x.Symbol)
             self.dataBySymbol[x.Symbol].roc.Update(self.Time,x.Price)
             
             if self.dataBySymbol[x.Symbol].IsReady:
                 #https://docs.python.org/3/library/heapq.html
                self.selected.append(x.Symbol)

         self.selected = sorted(self.selected,key = lambda x :self.dataBySymbol[x].rocd.Current.Value,reverse = True )[:5]
        
         
         self.Debug(str(self.selected))
         return self.selected
         
    def OnData(self, data):
        for symbol in self.selected:
            if not self.Portfolio[symbol].Invested:
                self.SetHoldings(symbol,1/len(self.selected))
    
    def OnSecuritiesChanged(self,changes):
        for x in changes.RemovedSecurities:
            self.dataBySymbol.pop(x.Symbol,None)
            self.Liquidate(x.Symbol)
class SymbolData:
    def __init__(self,algo,symbol):
        self.roc = RateOfChange(252)
        self.rocd = IndicatorExtensions.Of(Delay(21), self.roc)
        self.symbol = symbol
        history = algo.History(symbol,273,Resolution.Daily)
        if not  history.empty:
            for time, row in history.loc[symbol].iterrows():
                self.roc.Update(time,row['close'])
                
    @property
    def IsReady(self):
        return self.roc.IsReady
        return self.rocd.IsReady