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
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
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

        # liquidate positions
        for kvp in self.Portfolio:
            security_holding = kvp.Value 
            if security_holding.Quantity > 0:
                self.SetHoldings(secuity_holding.Symbol.Value, 0)

        percentage = 1 / d.Decimal(len(self.current_universe))
        for sym in self.current_universe:
            #self.Debug(sym+'  '+str(percentage))
            self.SetHoldings(sym, 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)