Overall Statistics
Total Trades
855
Average Win
1.40%
Average Loss
-0.67%
Compounding Annual Return
14.946%
Drawdown
23.900%
Expectancy
0.526
Net Profit
249.628%
Sharpe Ratio
0.84
Probabilistic Sharpe Ratio
23.512%
Loss Rate
51%
Win Rate
49%
Profit-Loss Ratio
2.10
Alpha
0.127
Beta
0.193
Annual Standard Deviation
0.207
Annual Variance
0.043
Information Ratio
-0.28
Tracking Error
0.256
Treynor Ratio
0.9
Total Fees
$859.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('DPZ',res).Symbol
        self.S1=self.AddEquity('WW',res).Symbol
        self.S2=self.AddEquity('HLF',res).Symbol
        self.S3=self.AddEquity('PM',res).Symbol
        self.S4=self.AddEquity('AZO',res).Symbol
        self.S5=self.AddEquity('ROST',res).Symbol
        self.S6=self.AddEquity('CF',res).Symbol
        self.S7=self.AddEquity('TJX',res).Symbol
        self.S8=self.AddEquity('SNBR',res).Symbol
        self.S9=self.AddEquity('AAPL',res).Symbol
        self.S10=self.AddEquity('SBH',res).Symbol
        self.S11=self.AddEquity('MA',res).Symbol
        self.S12=self.AddEquity('PII',res).Symbol
        self.S13=self.AddEquity('RGR',res).Symbol
        self.S14=self.AddEquity('REGN',res).Symbol
        self.S15=self.AddEquity('JBHT',res).Symbol
        self.S16=self.AddEquity('CBOE',res).Symbol
        self.S17=self.AddEquity('LMT',res).Symbol
        self.S18=self.AddEquity('CHH',res).Symbol
        self.S19=self.AddEquity('AZPN',res).Symbol
        self.S20=self.AddEquity('SCU',res).Symbol
        self.S21=self.AddEquity('VRSN',res).Symbol
        self.S22=self.AddEquity('SPGI',res).Symbol
        self.S23=self.AddEquity('SWBI',res).Symbol
        self.S24=self.AddEquity('DAL',res).Symbol
        self.S25=self.AddEquity('OSTK',res).Symbol
        self.S26=self.AddEquity('CCOI',res).Symbol
        self.S27=self.AddEquity('KKR',res).Symbol
        self.S28=self.AddEquity('JOE',res).Symbol
        self.S29=self.AddEquity('MTOR',res).Symbol
        self.S30=self.AddEquity('XPER',res).Symbol
        self.S31=self.AddEquity('MAR',res).Symbol
        self.S32=self.AddEquity('GILD',res).Symbol
        self.S33=self.AddEquity('MANH',res).Symbol
        self.S34=self.AddEquity('ENTA',res).Symbol
        self.S35=self.AddEquity('RAD',res).Symbol
        self.S36=self.AddEquity('PPC',res).Symbol
        self.S37=self.AddEquity('ABMD',res).Symbol
        self.S38=self.AddEquity('ABC',res).Symbol
        self.S39=self.AddEquity('FDS',res).Symbol
        self.S40=self.AddEquity('UTHR',res).Symbol
        self.S41=self.AddEquity('FPRX',res).Symbol
        self.S42=self.AddEquity('MIK',res).Symbol
        self.S43=self.AddEquity('CALM',res).Symbol
        self.S44=self.AddEquity('AEIS',res).Symbol
        self.S45=self.AddEquity('LGND',res).Symbol
        self.S46=self.AddEquity('RAMP',res).Symbol
        self.S47=self.AddEquity('HPQ',res).Symbol
        self.S48=self.AddEquity('CVA',res).Symbol
        self.S49=self.AddEquity('SSYS',res).Symbol
        self.S50=self.AddEquity('BLDR',res).Symbol
        self.S51=self.AddEquity('MSGN',res).Symbol
        self.S52=self.AddEquity('APAM',res).Symbol
        self.S53=self.AddEquity('INTU',res).Symbol
        self.S54=self.AddEquity('PENN',res).Symbol
        self.S55=self.AddEquity('HDS',res).Symbol
        self.S56=self.AddEquity('SANM',res).Symbol
        self.S57=self.AddEquity('BA',res).Symbol
        self.S58=self.AddEquity('SUPN',res).Symbol
        self.S59=self.AddEquity('CDE',res).Symbol
        self.S60=self.AddEquity('MO',res).Symbol
        self.S61=self.AddEquity('TREX',res).Symbol
        self.S62=self.AddEquity('BAX',res).Symbol
        self.S63=self.AddEquity('BEAT',res).Symbol
        self.S64=self.AddEquity('FIZZ',res).Symbol
        self.S65=self.AddEquity('NAV',res).Symbol
        self.S66=self.AddEquity('EXEL',res).Symbol
        self.S67=self.AddEquity('OEC',res).Symbol
        self.S68=self.AddEquity('TPL',res).Symbol
        self.S69=self.AddEquity('LNTH',res).Symbol
        self.S70=self.AddEquity('CORT',res).Symbol
        self.S71=self.AddEquity('HEAR',res).Symbol
        self.S72=self.AddEquity('NSP',res).Symbol
        self.S73=self.AddEquity('INVA',res).Symbol
        self.S74=self.AddEquity('HLNE',res).Symbol
        self.S75=self.AddEquity('UI',res).Symbol
        self.S76=self.AddEquity('VRTX',res).Symbol
        self.S77=self.AddEquity('MED',res).Symbol
        self.S78=self.AddEquity('YUM',res).Symbol
        self.S79=self.AddEquity('HCC',res).Symbol
        self.S80=self.AddEquity('SBUX',res).Symbol
        self.S81=self.AddEquity('DENN',res).Symbol
        self.S82=self.AddEquity('WHD',res).Symbol
        self.S83=self.AddEquity('CTXS',res).Symbol
        self.S84=self.AddEquity('CDNS',res).Symbol
        self.S85=self.AddEquity('CNS',res).Symbol
        self.S86=self.AddEquity('FTNT',res).Symbol
        self.S87=self.AddEquity('PZZA',res).Symbol
        self.S88=self.AddEquity('APPS',res).Symbol
        self.S89=self.AddEquity('ALGN',res).Symbol
        self.S90=self.AddEquity('CODX',res).Symbol

        self.signals = {'2012-01-03':{self.S0:0.33713,self.S1:0.01543,self.S2:0.07181,self.S3:0.03287,self.S4:0.54277},'2012-02-01':{self.S0:0.10536,self.S1:0.07944,self.S2:0.15991,self.S4:0.65529},'2012-03-01':{self.S0:0.02347,self.S2:0.18028,self.S1:0.11337,self.S3:0.03993,self.S4:0.64295},'2012-04-02':{self.S0:0.0594,self.S2:0.17261,self.S1:0.10284,self.S3:0.07888,self.S5:0.01195,self.S4:0.57431},'2012-05-01':{self.S0:0.00397,self.S1:0.08182,self.S2:0.14784,self.S4:0.52466,self.S3:0.18993,self.S5:0.05178},'2012-06-01':{self.S0:0.06151,self.S6:0.01751,self.S4:0.3197,self.S3:0.3837,self.S5:0.21758},'2012-07-02':{self.S0:0.14165,self.S6:0.03526,self.S4:0.16531,self.S3:0.38889,self.S5:0.22875,self.S7:0.04014},'2012-08-01':{self.S0:0.17951,self.S3:0.29481,self.S4:0.06511,self.S5:0.36062,self.S7:0.09994},'2012-09-04':{self.S0:0.15244,self.S3:0.20704,self.S8:0.05221,self.S7:0.10648,self.S5:0.48183},'2012-10-01':{self.S0:0.24364,self.S3:0.13742,self.S8:0.05685,self.S7:0.05336,self.S5:0.32574,self.S9:0.18299},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S0:0.44894,self.S4:0.01357,self.S7:0.32813,self.S3:0.19346,self.S1:0.00505,self.S10:0.01085},'2012-12-03':{self.S0:0.40001,self.S7:0.33922,self.S3:0.26076},'2013-01-02':{self.S0:0.46834,self.S7:0.40811,self.S3:0.12354},'2013-02-01':{self.S0:0.44475,self.S7:0.32523,self.S3:0.18551,self.S11:0.03479,self.S12:0.00972},'2013-03-01':{self.S0:0.41722,self.S13:0.14819,self.S3:0.01381,self.S14:0.24437,self.S7:0.17641},'2013-04-01':{self.S0:0.57324,self.S13:0.06613,self.S3:0.09985,self.S14:0.26078},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S0:0.40001,self.S13:0.10141,self.S15:0.02416,self.S4:0.05216,self.S14:0.42225},'2013-06-03':{self.S0:0.45535,self.S13:0.09387,self.S16:0.05213,self.S17:0.01369,self.S14:0.38495},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S0:0.30645,self.S13:0.02944,self.S16:0.34539,self.S14:0.31873},'2013-08-01':{self.S0:0.13852,self.S16:0.3695,self.S14:0.29221,self.S17:0.04712,self.S7:0.15265},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S0:0.1378,self.S16:0.27266,self.S15:0.03273,self.S17:0.3067,self.S5:0.0669,self.S18:0.00286,self.S14:0.15955,self.S19:0.02081},'2013-09-03':{self.S0:0.1394,self.S16:0.24611,self.S15:0.01651,self.S17:0.34243,self.S14:0.18751,self.S5:0.06804},'2013-10-01':{self.S0:0.18323,self.S13:0.02059,self.S16:0.11001,self.S15:0.08422,self.S17:0.3176,self.S18:0.05334,self.S14:0.23101},'2013-11-01':{self.S0:0.06491,self.S13:0.05746,self.S16:0.23862,self.S19:0.0251,self.S15:0.02085,self.S17:0.29969,self.S18:0.05341,self.S14:0.23997},'2013-12-02':{self.S20:0.02165,self.S0:0.0689,self.S13:0.07934,self.S19:0.0586,self.S16:0.26527,self.S21:0.01131,self.S17:0.37553,self.S22:0.03864,self.S18:0.07174,self.S11:0.00901},'2014-01-02':{self.S20:0.02457,self.S0:0.03244,self.S13:0.04153,self.S19:0.08595,self.S16:0.30003,self.S17:0.33321,self.S22:0.01027,self.S18:0.03708,self.S23:0.02538,self.S11:0.10953},'2014-02-03':{self.S0:0.12192,self.S13:0.03196,self.S19:0.13972,self.S16:0.38693,self.S22:0.04069,self.S18:0.14947,self.S23:0.01346,self.S24:0.11586},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S19:0.01173,self.S0:0.21032,self.S25:0.01572,self.S16:0.42369,self.S26:0.09108,self.S24:0.24531,self.S18:0.00215},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S27:0.06916,self.S19:0.01579,self.S0:0.35641,self.S16:0.0458,self.S26:0.05123,self.S24:0.29724,self.S28:0.01978,self.S22:0.13938,self.S18:0.00522},'2014-07-01':{self.S27:0.04372,self.S19:0.0439,self.S0:0.37746,self.S16:0.08006,self.S26:0.02087,self.S24:0.23668,self.S28:0.07026,self.S22:0.12706},'2014-08-01':{self.S0:0.26136,self.S19:0.00093,self.S29:0.0215,self.S16:0.03175,self.S26:0.10083,self.S30:0.04215,self.S24:0.35683,self.S18:0.02406,self.S20:0.16059},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S30:0.13204,self.S0:0.15355,self.S29:0.03597,self.S16:0.14153,self.S26:0.01016,self.S24:0.37939,self.S31:0.01531,self.S18:0.13204},'2014-09-02':{self.S30:0.12119,self.S0:0.14741,self.S29:0.04004,self.S16:0.12776,self.S26:0.01318,self.S24:0.39832,self.S31:0.01387,self.S18:0.13825},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S29:0.0199,self.S0:0.16035,self.S31:0.05506,self.S32:0.05972,self.S33:0.13886,self.S17:0.55077,self.S34:0.01534},'2015-03-02':{self.S29:0.03057,self.S0:0.10446,self.S31:0.09161,self.S4:0.04112,self.S32:0.06029,self.S33:0.11877,self.S17:0.53598,self.S34:0.01721},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S29:0.0317,self.S0:0.05735,self.S31:0.06273,self.S4:0.15095,self.S32:0.02497,self.S33:0.15796,self.S17:0.51435},'2015-05-01':{self.S29:0.00221,self.S0:0.12779,self.S35:0.12797,self.S31:0.18975,self.S32:0.08912,self.S33:0.29591,self.S4:0.16725},'2015-06-01':{self.S0:0.06581,self.S35:0.14177,self.S31:0.18643,self.S34:0.02333,self.S32:0.10791,self.S33:0.28593,self.S4:0.18881},'2015-07-01':{self.S0:0.11472,self.S31:0.16594,self.S34:0.05002,self.S35:0.13662,self.S32:0.16564,self.S33:0.2698,self.S4:0.09726},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S31:0.04559,self.S16:0.05053,self.S0:0.00735,self.S32:0.00406,self.S33:0.22058,self.S35:0.08614,self.S36:0.00646,self.S37:0.23221,self.S38:0.34707},'2015-10-01':{self.S31:0.01273,self.S16:0.07411,self.S4:0.32808,self.S33:0.22312,self.S36:0.02183,self.S37:0.34014},'2015-11-02':{self.S31:0.09535,self.S16:0.01118,self.S33:0.321,self.S4:0.5321,self.S39:0.04036},'2015-12-01':{self.S16:0.06509,self.S33:0.34109,self.S21:0.06582,self.S40:0.01552,self.S4:0.51248},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S16:0.00616,self.S41:0.00378,self.S21:0.31563,self.S0:0.32231,self.S3:0.20505,self.S42:0.14706},'2016-04-01':{self.S41:0.01792,self.S21:0.26376,self.S0:0.30096,self.S3:0.17083,self.S43:0.08367,self.S42:0.16287},'2016-05-02':{self.S21:0.44391,self.S41:0.09575,self.S0:0.23506,self.S43:0.10448,self.S42:0.1208},'2016-06-01':{self.S16:0.13233,self.S21:0.33157,self.S33:0.0699,self.S41:0.10207,self.S0:0.21049,self.S42:0.15363},'2016-07-01':{self.S16:0.27337,self.S21:0.36253,self.S41:0.05453,self.S0:0.30958},'2016-08-01':{self.S0:0.3801,self.S16:0.26469,self.S21:0.14122,self.S41:0.10013,self.S42:0.11385},'2016-09-01':{self.S0:0.38925,self.S16:0.11497,self.S33:0.05527,self.S41:0.08502,self.S44:0.35549},'2016-10-03':{self.S45:0.02708,self.S0:0.39113,self.S41:0.1167,self.S44:0.46509},'2016-11-01':{self.S0:0.67335,self.S21:0.07098,self.S41:0.15775,self.S4:0.09793},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S46:0.02297,self.S47:0.02111,self.S29:0.0182,self.S0:0.13443,self.S48:0.02516,self.S21:0.01727,self.S16:0.03545,self.S49:0.08851,self.S33:0.0224,self.S50:0.22821,self.S51:0.0103,self.S52:0.03404,self.S53:0.01581,self.S42:0.01941,self.S54:0.01777,self.S41:0.21015,self.S4:0.0141,self.S15:0.01796,self.S55:0.04673},'2017-02-01':{self.S47:0.02627,self.S29:0.02498,self.S0:0.02956,self.S48:0.042,self.S21:0.02717,self.S16:0.04691,self.S33:0.03869,self.S49:0.06694,self.S56:0.03981,self.S51:0.02139,self.S52:0.07279,self.S50:0.02499,self.S53:0.031,self.S42:0.06554,self.S54:0.03782,self.S57:0.04026,self.S41:0.01341,self.S4:0.03925,self.S58:0.31121},'2017-03-01':{self.S47:0.00936,self.S29:0.00933,self.S0:0.25953,self.S59:0.04519,self.S21:0.08087,self.S33:0.02064,self.S16:0.01362,self.S54:0.02323,self.S60:0.04379,self.S49:0.07831,self.S22:0.01879,self.S3:0.05848,self.S56:0.17141,self.S52:0.03644,self.S51:0.05866,self.S61:0.01243,self.S42:0.03398,self.S57:0.00797,self.S62:0.01797},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S59:0.00351,self.S0:0.1835,self.S63:0.20298,self.S16:0.18151,self.S60:0.25645,self.S3:0.13409,self.S56:0.03796},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S0:0.19948,self.S63:0.18406,self.S60:0.54939,self.S56:0.06706},'2017-07-03':{self.S0:0.19784,self.S63:0.20367,self.S60:0.51511,self.S56:0.08338},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S0:0.0936,self.S57:0.25745,self.S63:0.15722,self.S22:0.03503,self.S64:0.45669},'2017-08-01':{self.S0:0.10802,self.S57:0.25412,self.S63:0.14098,self.S22:0.04717,self.S64:0.44971},'2017-09-01':{self.S0:0.11943,self.S63:0.07304,self.S57:0.3047,self.S22:0.10861,self.S64:0.39421},'2017-10-02':{self.S65:0.03853,self.S0:0.15731,self.S63:0.09973,self.S57:0.2641,self.S64:0.31674,self.S22:0.12358},'2017-11-01':{self.S65:0.05365,self.S0:0.16691,self.S63:0.06777,self.S57:0.27393,self.S64:0.22023,self.S53:0.02125,self.S22:0.19625},'2017-12-01':{self.S54:0.06947,self.S65:0.01323,self.S0:0.10695,self.S63:0.04026,self.S60:0.05497,self.S47:0.06029,self.S57:0.28247,self.S64:0.17741,self.S66:0.13832,self.S22:0.05664},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S54:0.09121,self.S0:0.1021,self.S63:0.06353,self.S60:0.22308,self.S65:0.06092,self.S47:0.02629,self.S57:0.28359,self.S66:0.14928},'2018-01-02':{self.S54:0.1095,self.S0:0.09639,self.S63:0.05928,self.S60:0.21648,self.S65:0.06393,self.S47:0.00914,self.S57:0.29907,self.S66:0.14621},'2018-02-01':{self.S54:0.06756,self.S67:0.05888,self.S68:0.16698,self.S0:0.05395,self.S63:0.02445,self.S57:0.37086,self.S60:0.04461,self.S65:0.01446,self.S47:0.01019,self.S66:0.09309,self.S22:0.09499},'2018-03-01':{self.S68:0.23725,self.S0:0.04069,self.S57:0.56184,self.S47:0.0491,self.S65:0.01238,self.S69:0.05577,self.S70:0.04296},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S54:0.04767,self.S67:0.06016,self.S68:0.25976,self.S57:0.27748,self.S71:0.0305,self.S0:0.11235,self.S65:0.02637,self.S64:0.03926,self.S72:0.14645},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S54:0.08118,self.S21:0.08429,self.S68:0.21551,self.S57:0.31527,self.S71:0.01184,self.S0:0.06295,self.S72:0.13514,self.S64:0.09382},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S21:0.10211,self.S0:0.03211,self.S57:0.39537,self.S68:0.09762,self.S73:0.03642,self.S71:0.00569,self.S8:0.01468,self.S74:0.20328,self.S64:0.11273},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S21:0.20964,self.S0:0.00654,self.S57:0.4096,self.S68:0.04912,self.S73:0.08988,self.S71:0.018,self.S74:0.21723},'2019-02-01':{self.S21:0.23078,self.S0:0.03632,self.S68:0.09824,self.S57:0.41031,self.S73:0.04556,self.S71:0.02102,self.S74:0.15777},'2019-03-01':{self.S21:0.04817,self.S68:0.0952,self.S57:0.25964,self.S74:0.18997,self.S72:0.19432,self.S75:0.10008,self.S71:0.01205,self.S76:0.02558,self.S77:0.07501},'2019-04-01':{self.S21:0.05123,self.S68:0.18513,self.S78:0.11318,self.S57:0.1379,self.S74:0.11665,self.S72:0.18372,self.S75:0.11327,self.S71:0.0063,self.S77:0.09262},'2019-05-01':{self.S21:0.10255,self.S78:0.13145,self.S68:0.1383,self.S74:0.17241,self.S75:0.14689,self.S57:0.08328,self.S77:0.10245,self.S72:0.12268},'2019-06-03':{self.S21:0.19389,self.S68:0.14313,self.S72:0.24866,self.S74:0.18572,self.S79:0.22861},'2019-06-26':{self.TLT:1.0},'2019-07-29':{self.S21:0.04032,self.S68:0.04394,self.S78:0.02748,self.S71:0.00887,self.S72:0.37133,self.S80:0.11694,self.S5:0.08624,self.S74:0.18288,self.S79:0.09898,self.S11:0.02303},'2019-08-01':{self.S21:0.05785,self.S71:0.01494,self.S68:0.08471,self.S81:0.16058,self.S79:0.09219,self.S80:0.18995,self.S5:0.08629,self.S74:0.19823,self.S72:0.11527},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S21:0.02686,self.S78:0.03431,self.S81:0.20722,self.S79:0.01094,self.S33:0.06572,self.S74:0.25886,self.S80:0.27573,self.S72:0.09384,self.S71:0.02651},'2019-09-03':{self.S21:0.02217,self.S78:0.03233,self.S81:0.21016,self.S79:0.0014,self.S33:0.04868,self.S74:0.29507,self.S80:0.25624,self.S72:0.11489,self.S71:0.01906},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S81:0.10987,self.S80:0.08136,self.S33:0.02928,self.S79:0.05002,self.S11:0.14479,self.S74:0.19318,self.S75:0.05196,self.S4:0.33955},'2019-11-01':{self.S81:0.08237,self.S80:0.09484,self.S33:0.0138,self.S79:0.01248,self.S22:0.02134,self.S11:0.1646,self.S74:0.19925,self.S75:0.05557,self.S4:0.35575},'2019-12-02':{self.S81:0.05216,self.S0:0.11311,self.S75:0.2084,self.S80:0.17763,self.S68:0.0396,self.S33:0.07763,self.S11:0.33147},'2020-01-02':{self.S81:0.09816,self.S0:0.05101,self.S75:0.17057,self.S80:0.23462,self.S68:0.06175,self.S77:0.02989,self.S11:0.354},'2020-02-03':{self.S21:0.24243,self.S81:0.06852,self.S75:0.10013,self.S77:0.01031,self.S80:0.23833,self.S33:0.01516,self.S22:0.30695,self.S82:0.01818},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S21:0.03155,self.S0:0.17778,self.S75:0.17851,self.S83:0.15278,self.S84:0.30434,self.S4:0.15503},'2020-05-01':{self.S21:0.34888,self.S0:0.16682,self.S85:0.00364,self.S75:0.34188,self.S83:0.13879},'2020-06-01':{self.S21:0.00203,self.S75:0.24926,self.S0:0.18253,self.S33:0.07467,self.S85:0.09892,self.S86:0.3926},'2020-07-01':{self.S87:0.06068,self.S75:0.23544,self.S33:0.08102,self.S85:0.16257,self.S86:0.46029},'2020-08-03':{self.S87:0.11271,self.S75:0.00386,self.S88:0.88343},'2020-09-01':{self.S75:0.23693,self.S87:0.3102,self.S22:0.31142,self.S4:0.14144},'2020-10-01':{self.S75:0.07836,self.S87:0.10209,self.S0:0.22603,self.S22:0.59352},'2020-11-02':{self.S75:0.23295,self.S0:0.18771,self.S52:0.09063,self.S22:0.47001,self.S89:0.01871},'2020-12-01':{self.S75:0.19107,self.S0:0.06405,self.S87:0.07435,self.S52:0.19548,self.S90:0.08243,self.S22:0.39262}}
        
        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)