Overall Statistics
import datetime

class IndicatorAlpha:
    # This alpha just tries to recreate a buggy trade
    def __init__(self):
        self.indicator = {}
    
    def Update(self, algorithm, slice):
        return []

    def OnSecuritiesChanged(self, algorithm, changes):
        for removed in changes.RemovedSecurities:
            if removed.Symbol in self.indicator:
                del self.indicator[removed.Symbol]

        for added in changes.AddedSecurities:
            indicator = IndicatorExtensions.Times(algorithm.CMO(added.Symbol, 24, Resolution.Minute), -1)
            #algorithm.Log(f"Created indicator {indicator}")
            self.indicator[added.Symbol] = indicator



class SleepyRedSnake(QCAlgorithm):

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

        self.AddAlpha(IndicatorAlpha())

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

        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetUniverseSelection(QC500UniverseSelectionModel())


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''

        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)