Overall Statistics
Total Trades
619
Average Win
0.22%
Average Loss
-0.31%
Compounding Annual Return
-52.328%
Drawdown
26.700%
Expectancy
-0.139
Net Profit
-12.003%
Sharpe Ratio
-1.195
Probabilistic Sharpe Ratio
11.519%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.72
Alpha
-0.707
Beta
1.077
Annual Standard Deviation
0.334
Annual Variance
0.111
Information Ratio
-2.148
Tracking Error
0.319
Treynor Ratio
-0.37
Total Fees
$1049.98
Estimated Strategy Capacity
$5800000.00
Lowest Capacity Asset
MDIAV XAUQQ1QHPEUD
class WellDressedBrownShark(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 5, 25)
        self.SetCash(100000) 
        self.AddEquity("SPY", Resolution.Minute)
        
        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
        self.UniverseSettings.Resolution = Resolution.Minute
        
        self.AddAlpha(CustomAlpha())
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(0.05))
        
        self.SetSecurityInitializer(lambda security: security.SetMarketPrice(self.GetLastKnownPrice(security)))
        
    def CoarseSelectionFunction(self, coarse):
        sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
        filtered = [ x.Symbol for x in sortedByDollarVolume if x.HasFundamentalData ]
        return filtered[:50]
    
    def FineSelectionFunction(self, fine):
        sortedByPeRatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=False)
        return [ x.Symbol for x in sortedByPeRatio[:10] ]
        

class CustomAlpha(AlphaModel):
    
    def __init__(self):
        self.day = -1
        self.selected = []
        
    def Update(self, algorithm, data):
        if algorithm.Time.day == self.day:
            return []
        self.day = algorithm.Time.day
        
        return [Insight.Price(symbol, Expiry.EndOfDay, InsightDirection.Up) for symbol in self.selected]
        
    def OnSecuritiesChanged(self, algorithm, changes):
        [self.selected.append(change.Symbol) for change in changes.AddedSecurities]
        [self.selected.remove(change.Symbol) for change in changes.RemovedSecurities if change.Symbol in self.selected]