Overall Statistics
Total Trades
1826
Average Win
0.02%
Average Loss
0.00%
Compounding Annual Return
17.542%
Drawdown
32.200%
Expectancy
1.024
Net Profit
144.930%
Sharpe Ratio
0.914
Probabilistic Sharpe Ratio
34.998%
Loss Rate
58%
Win Rate
42%
Profit-Loss Ratio
3.83
Alpha
0.005
Beta
0.938
Annual Standard Deviation
0.142
Annual Variance
0.02
Information Ratio
-0.232
Tracking Error
0.012
Treynor Ratio
0.138
Total Fees
$1851.98
Estimated Strategy Capacity
$860000000.00
Lowest Capacity Asset
EQT R735QTJ8XC9X
class RobinWigglesworthTrillionsAlgorithm(QCAlgorithm):

    def Initialize(self):
        # The Paris Agreement opened for signature
        self.SetStartDate(2016, 4, 22)
        
        self.SetCash(1_000_000)
        
        self.month = 0
        self.weights = {}

        self.spy = self.AddEquity("SPY").Symbol
        spyUniverse = self.Universe.ETF(self.spy, self.UniverseSettings, self.Top500)
        self.AddUniverse(spyUniverse, self.SelectFine)


    def Top500(self, constituents):

        if self.month == self.Time.month:
            return Universe.Unchanged
        self.month = self.Time.month

        selected = sorted([c for c in constituents if c.Weight],
            key=lambda c: c.Weight, reverse=True)[:500]

        self.weights = {c.Symbol: c.Weight for c in selected}

        return [c.Symbol for c in selected]


    def SelectFine(self, fine):

        for f in fine:
            industry = f.AssetClassification.MorningstarIndustryGroupCode
            if industry != MorningstarIndustryGroupCode.OilAndGas:
                self.weights.pop(f.Symbol, None)

        msg = f'{self.Time} :: The Oil and Gas Industry has {len(self.weights)} stocks and represents {sum(self.weights.values()):.2%} of the S&P500'
        self.Log(msg)
        return [k for k,v in self.weights.items()]


    def OnData(self, data):
        if not self.weights:
            return

        self.weights[self.spy] = -1
        
        self.SetHoldings([PortfolioTarget(s, -q)
            for s,q in self.weights.items()])
                
        self.weights.clear()