Overall Statistics
Total Trades
47
Average Win
0.39%
Average Loss
-0.35%
Compounding Annual Return
102.984%
Drawdown
7.700%
Expectancy
0.108
Net Profit
6.335%
Sharpe Ratio
2.935
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
1.10
Alpha
-0.966
Beta
87.443
Annual Standard Deviation
0.25
Annual Variance
0.063
Information Ratio
2.86
Tracking Error
0.25
Treynor Ratio
0.008
Total Fees
$54.22
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)