Overall Statistics
import numpy as np
import decimal as d

class BasicTemplateAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2018,4,6) #(2013,1,1)
        #self.SetEndDate(2013,12,31)

        self.backtestSymbolsPerDay = {}
        self.current_universe = []

        self.UniverseSettings.Resolution = Resolution.Hour;
        self.AddUniverse("my-dropbox-universe", self.universeGetter)

    def universeGetter(self, date):

        # handle live mode file format
        if self.LiveMode:
            # work on this later
            return self.current_universe

        # backtest - first cache the entire file
        #if len(self.backtestSymbolsPerDay) == 0:
        #    str = self.Download("https://www.dropbox.com/s/rmiiktz0ntpff3a/daily-stock-picker-backtest.csv?dl=1")
        #    for line in str.splitlines():
        #        data = line.split(',')
        #        self.backtestSymbolsPerDay[data[0]] = data[1:]
        # Dummmy this up for now
        if len(self.backtestSymbolsPerDay) == 0:
            self.backtestSymbolsPerDay['20180406'] = ['ABMD', 'BZUN', 'CRM', 'NOW']
            self.backtestSymbolsPerDay['20180413'] = ['PAYC', 'ULTI', 'CRM', 'ADBE']
            self.backtestSymbolsPerDay['20180420'] = ['PAYC', 'ADBE', 'CRM', 'RHT']
            self.backtestSymbolsPerDay['20180427'] = ['PAYC', 'ADBE', 'RHT', 'BOOT']

        index = date.strftime("%Y%m%d")
        #self.Debug(index)
        self.current_universe = self.backtestSymbolsPerDay.get(index, self.current_universe)

        return self.current_universe

    def OnData(self, slice):
        if slice.Bars.Count == 0: return
        if self.changes == None: return

        # start fresh
        self.Liquidate()

        percentage = 1 / d.Decimal(slice.Bars.Count)
        for tradeBar in slice.Bars.Values:
            self.SetHoldings(tradeBar.Symbol, percentage)

        # reset changes
        self.changes = None
        
        self.Debug(str(self.Time) +'  '+'end OnData')
        
    def OnSecuritiesChanged(self, changes):
        self.changes = changes
        
    def OnEndOfAlgorithm(self):
        self.Log('End captured')
        for sym in self.current_universe:
            self.Log(sym)