Overall Statistics
Total Trades
594
Average Win
3.03%
Average Loss
-1.63%
Compounding Annual Return
15.530%
Drawdown
40.600%
Expectancy
0.232
Net Profit
265.930%
Sharpe Ratio
0.644
Probabilistic Sharpe Ratio
10.166%
Loss Rate
57%
Win Rate
43%
Profit-Loss Ratio
1.86
Alpha
0.16
Beta
0.301
Annual Standard Deviation
0.363
Annual Variance
0.132
Information Ratio
-0.031
Tracking Error
0.383
Treynor Ratio
0.777
Total Fees
$626.57
import pandas as pd
class LiquidUniverseSelection(QCAlgorithm):
    
    def Initialize(self):
        self.SetWarmup(10)
        self.SetBenchmark("QQQ")
        self.SetStartDate(2011, 12, 31)
        # self.SetEndDate(2012, 5, 8)
        self.SetCash(5000) 
        res1 = Resolution.Minute
        res = Resolution.Minute
        self.MRKT = self.AddEquity('SPY', res1).Symbol  # market
        self.TLT = self.AddEquity('TLT', res1).Symbol  # market
        self.S0=self.AddEquity('VHC',res).Symbol
        self.S1=self.AddEquity('VRSN',res).Symbol
        self.S2=self.AddEquity('IMGN',res).Symbol
        self.S3=self.AddEquity('ITT',res).Symbol
        self.S4=self.AddEquity('EXAS',res).Symbol
        self.S5=self.AddEquity('ARNA',res).Symbol
        self.S6=self.AddEquity('SGEN',res).Symbol
        self.S7=self.AddEquity('CHTR',res).Symbol
        self.S8=self.AddEquity('SRPT',res).Symbol
        self.S9=self.AddEquity('PODD',res).Symbol
        self.S10=self.AddEquity('CSOD',res).Symbol
        self.S11=self.AddEquity('TSLA',res).Symbol
        self.S12=self.AddEquity('ALNY',res).Symbol
        self.S13=self.AddEquity('MTEM',res).Symbol
        self.S14=self.AddEquity('CLDX',res).Symbol
        self.S15=self.AddEquity('PCRX',res).Symbol
        self.S16=self.AddEquity('NKTR',res).Symbol
        self.S17=self.AddEquity('DXCM',res).Symbol
        self.S18=self.AddEquity('VNDA',res).Symbol
        self.S19=self.AddEquity('SPLK',res).Symbol
        self.S20=self.AddEquity('NVAX',res).Symbol
        self.S21=self.AddEquity('CREE',res).Symbol
        self.S22=self.AddEquity('CDMO',res).Symbol
        self.S23=self.AddEquity('INO',res).Symbol
        self.S24=self.AddEquity('ACAD',res).Symbol
        self.S25=self.AddEquity('FCEL',res).Symbol
        self.S26=self.AddEquity('INVA',res).Symbol
        self.S27=self.AddEquity('BCRX',res).Symbol
        self.S28=self.AddEquity('PEIX',res).Symbol
        self.S29=self.AddEquity('VRTX',res).Symbol
        self.S30=self.AddEquity('AMED',res).Symbol
        self.S31=self.AddEquity('YELP',res).Symbol
        self.S32=self.AddEquity('INCY',res).Symbol
        self.S33=self.AddEquity('PFPT',res).Symbol
        self.S34=self.AddEquity('ARWR',res).Symbol
        self.S35=self.AddEquity('NBIX',res).Symbol
        self.S36=self.AddEquity('OMER',res).Symbol
        self.S37=self.AddEquity('EQC',res).Symbol
        self.S38=self.AddEquity('ICPT',res).Symbol
        self.S39=self.AddEquity('CSII',res).Symbol
        self.S40=self.AddEquity('PTCT',res).Symbol
        self.S41=self.AddEquity('HALO',res).Symbol
        self.S42=self.AddEquity('XLRN',res).Symbol
        self.S43=self.AddEquity('TGTX',res).Symbol
        self.S44=self.AddEquity('PACB',res).Symbol
        self.S45=self.AddEquity('RVNC',res).Symbol
        self.S46=self.AddEquity('ZEN',res).Symbol
        self.S47=self.AddEquity('EGRX',res).Symbol
        self.S48=self.AddEquity('CHRS',res).Symbol
        self.S49=self.AddEquity('RAMP',res).Symbol
        self.S50=self.AddEquity('CARA',res).Symbol
        self.S51=self.AddEquity('BLDR',res).Symbol
        self.S52=self.AddEquity('CDE',res).Symbol
        self.S53=self.AddEquity('TDOC',res).Symbol
        self.S54=self.AddEquity('ADSK',res).Symbol
        self.S55=self.AddEquity('AZPN',res).Symbol
        self.S56=self.AddEquity('GLIBA',res).Symbol
        self.S57=self.AddEquity('ZGNX',res).Symbol
        self.S58=self.AddEquity('FOLD',res).Symbol
        self.S59=self.AddEquity('BOX',res).Symbol
        self.S60=self.AddEquity('AXDX',res).Symbol
        self.S61=self.AddEquity('PRO',res).Symbol
        self.S62=self.AddEquity('RIOT',res).Symbol
        self.S63=self.AddEquity('RETA',res).Symbol
        self.S64=self.AddEquity('TVTY',res).Symbol
        self.S65=self.AddEquity('YEXT',res).Symbol
        self.S66=self.AddEquity('DVAX',res).Symbol
        self.S67=self.AddEquity('FATE',res).Symbol
        self.S68=self.AddEquity('BPMC',res).Symbol
        self.S69=self.AddEquity('TNDM',res).Symbol
        self.S70=self.AddEquity('QCOM',res).Symbol
        self.S71=self.AddEquity('VIAV',res).Symbol
        self.S72=self.AddEquity('USAT',res).Symbol
        self.S73=self.AddEquity('KPTI',res).Symbol
        self.S74=self.AddEquity('SAGE',res).Symbol
        self.S75=self.AddEquity('CCXI',res).Symbol
        self.S76=self.AddEquity('DOMO',res).Symbol
        self.S77=self.AddEquity('RCUS',res).Symbol
        self.S78=self.AddEquity('MCRB',res).Symbol
        self.S79=self.AddEquity('OTRK',res).Symbol
        self.S80=self.AddEquity('INSG',res).Symbol
        self.S81=self.AddEquity('WKHS',res).Symbol
        self.S82=self.AddEquity('OCUL',res).Symbol
        self.S83=self.AddEquity('VERI',res).Symbol
        self.S84=self.AddEquity('FUBO',res).Symbol
        self.S85=self.AddEquity('MTCH',res).Symbol
        self.S86=self.AddEquity('NVTA',res).Symbol

        self.signals = {'2012-01-03':{self.S0:0.66614,self.S1:0.33386},'2012-02-01':{self.S1:0.53775,self.S0:0.46225},'2012-03-01':{self.S1:0.64778,self.S2:0.06602,self.S0:0.20535,self.S3:0.08085},'2012-04-02':{self.S1:0.49859,self.S0:0.50141},'2012-05-01':{self.S0:1.0},'2012-06-01':{self.S0:0.77512,self.S4:0.17532,self.S5:0.04956},'2012-07-02':{self.S0:0.48932,self.S4:0.2081,self.S5:0.05621,self.S6:0.24637},'2012-08-01':{self.S0:0.28634,self.S4:0.33398,self.S6:0.37969},'2012-09-04':{self.S0:0.04126,self.S6:0.20678,self.S7:0.75196},'2012-10-01':{self.S6:0.01758,self.S5:0.17122,self.S7:0.81121},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S8:0.02792,self.S0:0.24951,self.S9:0.10168,self.S5:0.62089},'2012-12-03':{self.S8:0.03292,self.S0:0.17492,self.S10:0.13992,self.S9:0.182,self.S5:0.47023},'2013-01-02':{self.S8:0.01703,self.S0:0.11502,self.S10:0.30346,self.S9:0.00514,self.S5:0.55935},'2013-02-01':{self.S8:0.0132,self.S0:0.16913,self.S10:0.23948,self.S11:0.0079,self.S4:0.17602,self.S5:0.39427},'2013-03-01':{self.S8:0.01979,self.S0:0.17508,self.S10:0.2164,self.S4:0.12658,self.S5:0.34336,self.S12:0.11878},'2013-04-01':{self.S2:0.1517,self.S10:0.32117,self.S11:0.04156,self.S13:0.09654,self.S12:0.38903},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S10:0.18608,self.S8:0.03964,self.S11:0.4552,self.S14:0.31908},'2013-06-03':{self.S10:0.24219,self.S8:0.03628,self.S11:0.38725,self.S14:0.33428},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S10:0.1402,self.S15:0.1449,self.S8:0.02531,self.S11:0.35083,self.S14:0.33875},'2013-08-01':{self.S10:0.17291,self.S16:0.00335,self.S17:0.14393,self.S15:0.32027,self.S8:0.02156,self.S11:0.06544,self.S14:0.27255},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S8:0.01601,self.S14:0.38145,self.S15:0.22249,self.S13:0.04272,self.S10:0.33733},'2013-09-03':{self.S8:0.01382,self.S14:0.31543,self.S15:0.29289,self.S13:0.03081,self.S10:0.34705},'2013-10-01':{self.S8:0.01854,self.S14:0.45783,self.S15:0.20634,self.S13:0.02535,self.S10:0.29195},'2013-11-01':{self.S17:0.03356,self.S8:0.01693,self.S14:0.15711,self.S15:0.32957,self.S13:0.00671,self.S10:0.25143,self.S12:0.20469},'2013-12-02':{self.S14:0.19173,self.S17:0.1643,self.S12:0.17617,self.S15:0.45396,self.S13:0.01376},'2014-01-02':{self.S14:0.17256,self.S8:0.00281,self.S17:0.17997,self.S12:0.16769,self.S15:0.45064,self.S13:0.02632},'2014-02-03':{self.S18:0.01948,self.S19:0.04724,self.S14:0.11758,self.S8:0.01693,self.S17:0.36856,self.S20:0.15391,self.S12:0.221,self.S21:0.0553},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S8:0.05517,self.S22:0.02171,self.S23:0.13447,self.S12:0.30713,self.S18:0.06711,self.S20:0.19552,self.S24:0.21889},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S18:0.08981,self.S22:0.06663,self.S8:0.07461,self.S14:0.17085,self.S20:0.3079,self.S25:0.06926,self.S26:0.02468,self.S23:0.19626},'2014-07-01':{self.S18:0.14404,self.S27:0.07281,self.S28:0.0195,self.S22:0.08208,self.S8:0.08787,self.S14:0.12654,self.S20:0.30494,self.S25:0.1166,self.S26:0.04562},'2014-08-01':{self.S18:0.10892,self.S27:0.03914,self.S8:0.0224,self.S29:0.01677,self.S14:0.07729,self.S20:0.0327,self.S30:0.02895,self.S25:0.11724,self.S31:0.23451,self.S32:0.00325,self.S33:0.31884},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S27:0.09012,self.S29:0.01257,self.S34:0.32747,self.S23:0.14037,self.S35:0.00523,self.S24:0.27235,self.S25:0.11904,self.S20:0.03285},'2014-09-02':{self.S27:0.08405,self.S29:0.00932,self.S34:0.3286,self.S23:0.14034,self.S35:0.00818,self.S24:0.27185,self.S25:0.13485,self.S20:0.02281},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S36:0.03318,self.S37:0.06778,self.S33:0.36313,self.S34:0.01174,self.S23:0.00903,self.S20:0.30008,self.S38:0.02309,self.S4:0.00126,self.S24:0.19071},'2015-03-02':{self.S36:0.0521,self.S33:0.44795,self.S34:0.00677,self.S23:0.03001,self.S20:0.3252,self.S38:0.02434,self.S39:0.11363},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S36:0.1642,self.S33:0.4119,self.S37:0.08966,self.S34:0.0432,self.S20:0.14326,self.S38:0.03779,self.S23:0.10999},'2015-05-01':{self.S36:0.20026,self.S33:0.42074,self.S34:0.05069,self.S20:0.27837,self.S38:0.04996},'2015-06-01':{self.S34:0.02397,self.S33:0.45711,self.S36:0.11457,self.S23:0.08292,self.S40:0.13037,self.S38:0.05502,self.S24:0.13604},'2015-07-01':{self.S34:0.11664,self.S33:0.39218,self.S36:0.13973,self.S23:0.02856,self.S40:0.09375,self.S41:0.19168,self.S38:0.03746},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S34:0.02575,self.S36:0.03695,self.S42:0.11177,self.S43:0.17011,self.S27:0.33797,self.S4:0.13515,self.S24:0.14876,self.S40:0.03353},'2015-10-01':{self.S43:0.47061,self.S27:0.16171,self.S4:0.36769},'2015-11-02':{self.S43:0.89555,self.S44:0.10037,self.S27:0.00407},'2015-12-01':{self.S45:0.0177,self.S36:0.04745,self.S8:0.04464,self.S42:0.21836,self.S43:0.42398,self.S44:0.24786},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S36:0.33763,self.S43:0.66237},'2016-04-01':{self.S36:0.44852,self.S43:0.55148},'2016-05-02':{self.S24:0.61246,self.S43:0.38754},'2016-06-01':{self.S46:0.29638,self.S47:0.70362},'2016-07-01':{self.S46:0.50693,self.S47:0.49307},'2016-08-01':{self.S46:0.04423,self.S33:0.58539,self.S47:0.37038},'2016-09-01':{self.S48:0.29218,self.S8:0.01233,self.S33:0.69549},'2016-10-03':{self.S48:0.20059,self.S8:0.21339,self.S33:0.58603},'2016-11-01':{self.S48:0.2195,self.S8:0.09796,self.S33:0.68254},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S48:0.02566,self.S49:0.71623,self.S8:0.2581},'2017-02-01':{self.S48:0.01624,self.S50:0.04297,self.S8:0.35078,self.S51:0.59},'2017-03-01':{self.S50:0.24425,self.S45:0.13932,self.S8:0.32302,self.S52:0.29341},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S8:0.14397,self.S53:0.07704,self.S54:0.77899},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S55:0.5572,self.S50:0.08928,self.S56:0.35351},'2017-07-03':{self.S55:0.26653,self.S56:0.73347},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S55:0.23492,self.S56:0.74233,self.S36:0.02275},'2017-08-01':{self.S55:0.2626,self.S56:0.72475,self.S36:0.01265},'2017-09-01':{self.S55:0.72537,self.S54:0.27463},'2017-10-02':{self.S55:0.72326,self.S36:0.0069,self.S54:0.2408,self.S57:0.02904},'2017-11-01':{self.S55:0.61857,self.S54:0.35331,self.S57:0.02812},'2017-12-01':{self.S55:0.87472,self.S57:0.03462,self.S54:0.09066},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S55:0.91836,self.S57:0.03933,self.S54:0.04232},'2018-01-02':{self.S55:0.91369,self.S57:0.03832,self.S54:0.04799},'2018-02-01':{self.S58:0.02217,self.S57:0.05261,self.S54:0.62335,self.S59:0.16291,self.S8:0.13895},'2018-03-01':{self.S57:0.04861,self.S54:0.47166,self.S59:0.27268,self.S60:0.06542,self.S50:0.0284,self.S8:0.11324},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S43:0.01518,self.S61:0.27349,self.S2:0.08781,self.S54:0.34519,self.S57:0.06516,self.S62:0.01916,self.S63:0.16165,self.S58:0.0089,self.S34:0.02345},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S61:0.07313,self.S2:0.16389,self.S54:0.46439,self.S57:0.06921,self.S63:0.16323,self.S36:0.03751,self.S34:0.02864},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S64:0.34036,self.S2:0.20679,self.S54:0.34274,self.S34:0.11011},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S2:0.04124,self.S34:0.95876},'2019-02-01':{self.S20:0.01152,self.S2:0.10291,self.S34:0.88557},'2019-03-01':{self.S65:0.1806,self.S66:0.10946,self.S67:0.64868,self.S12:0.06127},'2019-04-01':{self.S67:0.78349,self.S12:0.13325,self.S68:0.08326},'2019-05-01':{self.S67:0.54103,self.S69:0.45623,self.S12:0.00274},'2019-06-03':{self.S63:0.6775,self.S58:0.08432,self.S70:0.23817},'2019-06-26':{self.TLT:1.0},'2019-07-29':{self.S71:0.1489,self.S63:0.38418,self.S70:0.46692},'2019-08-01':{self.S71:0.21966,self.S70:0.36877,self.S63:0.41156},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S70:0.46567,self.S63:0.37694,self.S72:0.0112,self.S50:0.14619},'2019-09-03':{self.S70:0.50598,self.S63:0.32836,self.S72:0.02196,self.S50:0.1437},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S70:0.34566,self.S63:0.65434},'2019-11-01':{self.S70:0.40682,self.S63:0.59318},'2019-12-02':{self.S73:0.24043,self.S74:0.31164,self.S44:0.44793},'2020-01-02':{self.S73:0.44576,self.S44:0.55424},'2020-02-03':{self.S73:0.26128,self.S44:0.73872},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S63:0.84642,self.S67:0.15358},'2020-05-01':{self.S63:0.79184,self.S67:0.20816},'2020-06-01':{self.S49:0.25035,self.S63:0.62526,self.S75:0.12439},'2020-07-01':{self.S63:0.80539,self.S20:0.19461},'2020-08-03':{self.S43:0.02972,self.S76:0.22253,self.S63:0.27377,self.S77:0.06763,self.S20:0.40634},'2020-09-01':{self.S78:0.00843,self.S79:0.60532,self.S80:0.38625},'2020-10-01':{self.S78:0.03088,self.S79:0.35787,self.S43:0.46379,self.S80:0.14745},'2020-11-02':{self.S78:0.02933,self.S81:0.21403,self.S79:0.32283,self.S43:0.37506,self.S80:0.05875},'2020-12-01':{self.S82:0.03318,self.S83:0.0759,self.S43:0.30095,self.S84:0.11994,self.S81:0.24943,self.S85:0.16199,self.S86:0.05862}}
        
        self.Schedule.On(
            self.DateRules.EveryDay(),
            self.TimeRules.AfterMarketOpen('SPY', 45),
            self.rebalance
        )
    
    def rebalance(self):
        currentDate = self.UtcTime.date()
        try:
            new_position = self.signals["{}".format(currentDate)]
        except:
            return
        # openOrders = self.Transactions.GetOpenOrders()
        # if len(openOrders) > 0:
        #     for x in openOrders:
        #          self.Transactions.CancelOrder(x.Id)
        invested = [ x.Symbol for x in self.Portfolio.Values if x.Invested ]
        invested = dict.fromkeys(invested, 0)
        invested.update(new_position)
        for sec, weight in invested.items():
            self.SetHoldings(sec, weight)
    
    # def OnOrderEvent(self, orderEvent):
    #     order = self.Transactions.GetOrderById(orderEvent.OrderId)
    #     if order.Type == OrderType.Market and orderEvent.Status == OrderStatus.Filled and order.Direction == OrderDirection.Buy: 
    #         price = order.Price
    #         quantity = order.Quantity
    #         self.StopMarketOrder(order.Symbol, quantity*-1, 0.92 * price)