Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-51.397
Tracking Error
0.047
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
class IndicatorAlpha:
    # This alpha just tries to recreate a buggy trade
    def __init__(self):
        self.symbol_data_by_symbol = {}
    
    def Update(self, algorithm, slice):
        for symbol, symbol_data in self.symbol_data_by_symbol.items():
            if symbol_data.IsReady:
                algorithm.Plot("Custom", str(symbol), symbol_data.indicator.Current.Value)
        
        return []

    def OnSecuritiesChanged(self, algorithm, changes):
        for removed in changes.RemovedSecurities:
            symbol_data = self.symbol_data_by_symbol.pop(removed.Symbol, None)
            if symbol_data:
                symbol_data.dispose()

        for added in changes.AddedSecurities:
            self.symbol_data_by_symbol[added.Symbol] = SymbolData(added.Symbol, algorithm)

class SymbolData:
    def __init__(self, symbol, algorithm):
        self.symbol = symbol
        self.algorithm = algorithm
        
        self.consolidator = TradeBarConsolidator(1)
        self.consolidator.DataConsolidated += self.consolidation_handler
        algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator)
        
        self.cmo = ChandeMomentumOscillator(24)
        self.indicator = IndicatorExtensions.Times(self.cmo, -1.0)
        
    def consolidation_handler(self, sender, consolidated):
        self.cmo.Update(consolidated.EndTime, consolidated.Close)

    @property        
    def IsReady(self):
        return self.cmo.IsReady
        
    def dispose(self):
        self.algorithm.SubscriptionManager.RemoveConsolidator(self.Symbol, self.consolidator)

class SleepyRedSnake(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 1)  # Set Start Date
        self.SetEndDate(2018, 1, 5)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash

        self.AddAlpha(IndicatorAlpha())

        self.SetExecution(ImmediateExecutionModel())
        self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())

        self.UniverseSettings.Resolution = Resolution.Daily
        #symbols = [ Symbol.Create("SPY", SecurityType.Equity, Market.USA) ]
        #self.AddUniverseSelection( ManualUniverseSelectionModel(symbols) )
        self.SetUniverseSelection(QC500UniverseSelectionModel())