Overall Statistics
Total Trades
27
Average Win
0%
Average Loss
0%
Compounding Annual Return
48.091%
Drawdown
2.600%
Expectancy
0
Net Profit
3.058%
Sharpe Ratio
3.023
Probabilistic Sharpe Ratio
66.775%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.426
Beta
-0.002
Annual Standard Deviation
0.141
Annual Variance
0.02
Information Ratio
1.489
Tracking Error
0.197
Treynor Ratio
-243.11
Total Fees
$27.00
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel

class DeltaMomentumUniverseSelectionModel(FundamentalUniverseSelectionModel):
    symboldict = {}

    def __init__(self):
        super().__init__(True)

    def SelectCoarse(self, algorithm, coarse):
        topDollarVolume = sorted(coarse, key=lambda k : k.DollarVolume, reverse=True)[:10]

        # When we get new symbols, we add them to the dict and warm up the indicator
        symbols = [x.Symbol for x in topDollarVolume if x.Symbol not in self.symboldict]
        history = algorithm.History(symbols, 136, Resolution.Daily)
        if not history.empty:
            history = history.close.unstack(0)
            for symbol in symbols:
                if str(symbol) not in history:
                    continue

                df = history[symbol].dropna()
                if not df.empty:
                    self.symboldict[symbol] = SymbolData(self, df)

        # Now, we update the dictionary with the latest data
        for x in coarse:
            symbol = x.Symbol
            if symbol in self.symboldict:
                self.symboldict[symbol].Update(x.EndTime, x.AdjustedPrice)

        topMOM = sorted(self.symboldict.items(), key=lambda x: x[1].DeltaMOM, reverse=True)[:200]
        return [x[0] for x in topMOM]
        

class SymbolData:
    def __init__(self, symbol, history):
        self.mom10 = Momentum(10)
        self.mom136 = Momentum(136)

        for time, close in history.iteritems():
            self.Update(time, close)

    def Update(self, time, close):
        self.mom10.Update(time, close)
        self.mom136.Update(time, close)


    @property
    def DeltaMOM(self):
        return self.mom10.Current.Value - self.mom136.Current.Value
    
    def __repr__(self):
        return f'{self.DeltaMOM}'
from universe import DeltaMomentumUniverseSelectionModel

class DynamicVentralCoil(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        # Set universe resolution
        self.UniverseSettings.Resolution = Resolution.Daily
        
        # Set universe selection and alpha
        self.AddUniverseSelection(DeltaMomentumUniverseSelectionModel())

    def OnSecuritiesChanged(self, changes):
        
        for security in changes.RemovedSecurities:
            self.Liquidate(security.Symbol)

        for security in changes.AddedSecurities:
            self.SetHoldings(security.Symbol, 0.005)