Overall Statistics |
Total Trades 842 Average Win 2.32% Average Loss -1.40% Compounding Annual Return 48.832% Drawdown 30.800% Expectancy 0.582 Net Profit 3467.567% Sharpe Ratio 1.893 Probabilistic Sharpe Ratio 94.449% Loss Rate 40% Win Rate 60% Profit-Loss Ratio 1.66 Alpha 0.493 Beta 0.244 Annual Standard Deviation 0.292 Annual Variance 0.085 Information Ratio 0.955 Tracking Error 0.323 Treynor Ratio 2.268 Total Fees $20085.39 |
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(100000) 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('HMSY',res).Symbol self.S1=self.AddEquity('DLTR',res).Symbol self.S2=self.AddEquity('INT',res).Symbol self.S3=self.AddEquity('AVA',res).Symbol self.S4=self.AddEquity('ARR',res).Symbol self.S5=self.AddEquity('MTH',res).Symbol self.S6=self.AddEquity('URI',res).Symbol self.S7=self.AddEquity('KLAC',res).Symbol self.S8=self.AddEquity('SNBR',res).Symbol self.S9=self.AddEquity('MOH',res).Symbol self.S10=self.AddEquity('TTC',res).Symbol self.S11=self.AddEquity('ARNA',res).Symbol self.S12=self.AddEquity('TWO',res).Symbol self.S13=self.AddEquity('LGF-A',res).Symbol self.S14=self.AddEquity('LNG',res).Symbol self.S15=self.AddEquity('TEX',res).Symbol self.S16=self.AddEquity('MSB',res).Symbol self.S17=self.AddEquity('SSYS',res).Symbol self.S18=self.AddEquity('RGR',res).Symbol self.S19=self.AddEquity('RHP',res).Symbol self.S20=self.AddEquity('BLK',res).Symbol self.S21=self.AddEquity('ALXN',res).Symbol self.S22=self.AddEquity('REGN',res).Symbol self.S23=self.AddEquity('MNST',res).Symbol self.S24=self.AddEquity('AAL',res).Symbol self.S25=self.AddEquity('LQDT',res).Symbol self.S26=self.AddEquity('MGLN',res).Symbol self.S27=self.AddEquity('GDOT',res).Symbol self.S28=self.AddEquity('LL',res).Symbol self.S29=self.AddEquity('HAIN',res).Symbol self.S30=self.AddEquity('IMGN',res).Symbol self.S31=self.AddEquity('ADSK',res).Symbol self.S32=self.AddEquity('CQP',res).Symbol self.S33=self.AddEquity('GNRC',res).Symbol self.S34=self.AddEquity('WU',res).Symbol self.S35=self.AddEquity('SRPT',res).Symbol self.S36=self.AddEquity('PENN',res).Symbol self.S37=self.AddEquity('GHC',res).Symbol self.S38=self.AddEquity('SCHL',res).Symbol self.S39=self.AddEquity('HLF',res).Symbol self.S40=self.AddEquity('CVI',res).Symbol self.S41=self.AddEquity('MDP',res).Symbol self.S42=self.AddEquity('CEQP',res).Symbol self.S43=self.AddEquity('PPG',res).Symbol self.S44=self.AddEquity('NFLX',res).Symbol self.S45=self.AddEquity('APO',res).Symbol self.S46=self.AddEquity('DDD',res).Symbol self.S47=self.AddEquity('ODP',res).Symbol self.S48=self.AddEquity('EQC',res).Symbol self.S49=self.AddEquity('PRDO',res).Symbol self.S50=self.AddEquity('DK',res).Symbol self.S51=self.AddEquity('SVC',res).Symbol self.S52=self.AddEquity('RLJ',res).Symbol self.S53=self.AddEquity('SPWR',res).Symbol self.S54=self.AddEquity('TSLA',res).Symbol self.S55=self.AddEquity('RAD',res).Symbol self.S56=self.AddEquity('SR',res).Symbol self.S57=self.AddEquity('DPZ',res).Symbol self.S58=self.AddEquity('NLSN',res).Symbol self.S59=self.AddEquity('CLDX',res).Symbol self.S60=self.AddEquity('SSNC',res).Symbol self.S61=self.AddEquity('ALNY',res).Symbol self.S62=self.AddEquity('USNA',res).Symbol self.S63=self.AddEquity('CUZ',res).Symbol self.S64=self.AddEquity('OMC',res).Symbol self.S65=self.AddEquity('UI',res).Symbol self.S66=self.AddEquity('ZG',res).Symbol self.S67=self.AddEquity('ACAD',res).Symbol self.S68=self.AddEquity('INCY',res).Symbol self.S69=self.AddEquity('AME',res).Symbol self.S70=self.AddEquity('CVA',res).Symbol self.S71=self.AddEquity('SOL',res).Symbol self.S72=self.AddEquity('YELP',res).Symbol self.S73=self.AddEquity('SNX',res).Symbol self.S74=self.AddEquity('NHI',res).Symbol self.S75=self.AddEquity('GME',res).Symbol self.S76=self.AddEquity('TMUS',res).Symbol self.S77=self.AddEquity('IEP',res).Symbol self.S78=self.AddEquity('GIII',res).Symbol self.S79=self.AddEquity('CW',res).Symbol self.S80=self.AddEquity('RXN',res).Symbol self.S81=self.AddEquity('TSCO',res).Symbol self.S82=self.AddEquity('VGR',res).Symbol self.S83=self.AddEquity('ILMN',res).Symbol self.S84=self.AddEquity('PEIX',res).Symbol self.S85=self.AddEquity('AVNT',res).Symbol self.S86=self.AddEquity('SKX',res).Symbol self.S87=self.AddEquity('UAA',res).Symbol self.S88=self.AddEquity('PPC',res).Symbol self.S89=self.AddEquity('TRGP',res).Symbol self.S90=self.AddEquity('TCP',res).Symbol self.S91=self.AddEquity('JOE',res).Symbol self.S92=self.AddEquity('OPI',res).Symbol self.S93=self.AddEquity('AMKR',res).Symbol self.S94=self.AddEquity('ACCO',res).Symbol self.S95=self.AddEquity('CENX',res).Symbol self.S96=self.AddEquity('SAFM',res).Symbol self.S97=self.AddEquity('WSM',res).Symbol self.S98=self.AddEquity('OSPN',res).Symbol self.S99=self.AddEquity('QLYS',res).Symbol self.S100=self.AddEquity('COLM',res).Symbol self.S101=self.AddEquity('NDLS',res).Symbol self.S102=self.AddEquity('PTCT',res).Symbol self.S103=self.AddEquity('GTN',res).Symbol self.S104=self.AddEquity('ABMD',res).Symbol self.S105=self.AddEquity('PGEN',res).Symbol self.S106=self.AddEquity('BLUE',res).Symbol self.S107=self.AddEquity('SSP',res).Symbol self.S108=self.AddEquity('VTRS',res).Symbol self.S109=self.AddEquity('AZPN',res).Symbol self.S110=self.AddEquity('DY',res).Symbol self.S111=self.AddEquity('AMBA',res).Symbol self.S112=self.AddEquity('MEI',res).Symbol self.S113=self.AddEquity('ITCI',res).Symbol self.S114=self.AddEquity('BLDR',res).Symbol self.S115=self.AddEquity('TREE',res).Symbol self.S116=self.AddEquity('WW',res).Symbol self.S117=self.AddEquity('PINC',res).Symbol self.S118=self.AddEquity('BKH',res).Symbol self.S119=self.AddEquity('DXC',res).Symbol self.S120=self.AddEquity('GE',res).Symbol self.S121=self.AddEquity('CSGS',res).Symbol self.S122=self.AddEquity('UIS',res).Symbol self.S123=self.AddEquity('TSE',res).Symbol self.S124=self.AddEquity('JCOM',res).Symbol self.S125=self.AddEquity('FR',res).Symbol self.S126=self.AddEquity('FPRX',res).Symbol self.S127=self.AddEquity('MIK',res).Symbol self.S128=self.AddEquity('CDE',res).Symbol self.S129=self.AddEquity('CLF',res).Symbol self.S130=self.AddEquity('GLPI',res).Symbol self.S131=self.AddEquity('IRM',res).Symbol self.S132=self.AddEquity('CPE',res).Symbol self.S133=self.AddEquity('AJG',res).Symbol self.S134=self.AddEquity('LKQ',res).Symbol self.S135=self.AddEquity('DLR',res).Symbol self.S136=self.AddEquity('SWX',res).Symbol self.S137=self.AddEquity('LNT',res).Symbol self.S138=self.AddEquity('EME',res).Symbol self.S139=self.AddEquity('EXAS',res).Symbol self.S140=self.AddEquity('TVTY',res).Symbol self.S141=self.AddEquity('BDC',res).Symbol self.S142=self.AddEquity('GEO',res).Symbol self.S143=self.AddEquity('CXW',res).Symbol self.S144=self.AddEquity('COTY',res).Symbol self.S145=self.AddEquity('ET',res).Symbol self.S146=self.AddEquity('SPSC',res).Symbol self.S147=self.AddEquity('IART',res).Symbol self.S148=self.AddEquity('TTMI',res).Symbol self.S149=self.AddEquity('VAR',res).Symbol self.S150=self.AddEquity('IIVI',res).Symbol self.S151=self.AddEquity('EW',res).Symbol self.S152=self.AddEquity('IDXX',res).Symbol self.S153=self.AddEquity('NVDA',res).Symbol self.S154=self.AddEquity('TMX',res).Symbol self.S155=self.AddEquity('IT',res).Symbol self.S156=self.AddEquity('NAV',res).Symbol self.S157=self.AddEquity('CSX',res).Symbol self.S158=self.AddEquity('UVV',res).Symbol self.S159=self.AddEquity('MASI',res).Symbol self.S160=self.AddEquity('TRU',res).Symbol self.S161=self.AddEquity('KNX',res).Symbol self.S162=self.AddEquity('GLIBA',res).Symbol self.S163=self.AddEquity('JKHY',res).Symbol self.S164=self.AddEquity('XENT',res).Symbol self.S165=self.AddEquity('BOX',res).Symbol self.S166=self.AddEquity('OMER',res).Symbol self.S167=self.AddEquity('NSA',res).Symbol self.S168=self.AddEquity('SGMO',res).Symbol self.S169=self.AddEquity('PETS',res).Symbol self.S170=self.AddEquity('RMD',res).Symbol self.S171=self.AddEquity('AOS',res).Symbol self.S172=self.AddEquity('SGMS',res).Symbol self.S173=self.AddEquity('CONN',res).Symbol self.S174=self.AddEquity('IQV',res).Symbol self.S175=self.AddEquity('ZGNX',res).Symbol self.S176=self.AddEquity('TDW',res).Symbol self.S177=self.AddEquity('OSTK',res).Symbol self.S178=self.AddEquity('CREE',res).Symbol self.S179=self.AddEquity('SQ',res).Symbol self.S180=self.AddEquity('NKTR',res).Symbol self.S181=self.AddEquity('CORT',res).Symbol self.S182=self.AddEquity('WYNN',res).Symbol self.S183=self.AddEquity('RIOT',res).Symbol self.S184=self.AddEquity('AWR',res).Symbol self.S185=self.AddEquity('KDP',res).Symbol self.S186=self.AddEquity('FOSL',res).Symbol self.S187=self.AddEquity('HEAR',res).Symbol self.S188=self.AddEquity('TNDM',res).Symbol self.S189=self.AddEquity('MEDP',res).Symbol self.S190=self.AddEquity('SEAS',res).Symbol self.S191=self.AddEquity('BCEI',res).Symbol self.S192=self.AddEquity('AIMC',res).Symbol self.S193=self.AddEquity('FTV',res).Symbol self.S194=self.AddEquity('ROL',res).Symbol self.S195=self.AddEquity('TWLO',res).Symbol self.S196=self.AddEquity('NSP',res).Symbol self.S197=self.AddEquity('WPC',res).Symbol self.S198=self.AddEquity('NEO',res).Symbol self.S199=self.AddEquity('CDNA',res).Symbol self.S200=self.AddEquity('FISV',res).Symbol self.S201=self.AddEquity('DORM',res).Symbol self.S202=self.AddEquity('BMY',res).Symbol self.S203=self.AddEquity('TFX',res).Symbol self.S204=self.AddEquity('XLNX',res).Symbol self.S205=self.AddEquity('BRC',res).Symbol self.S206=self.AddEquity('EHTH',res).Symbol self.S207=self.AddEquity('IIPR',res).Symbol self.S208=self.AddEquity('ATO',res).Symbol self.S209=self.AddEquity('UNIT',res).Symbol self.S210=self.AddEquity('XHR',res).Symbol self.S211=self.AddEquity('FOE',res).Symbol self.S212=self.AddEquity('CHGG',res).Symbol self.S213=self.AddEquity('WTRG',res).Symbol self.S214=self.AddEquity('DBD',res).Symbol self.S215=self.AddEquity('QCOM',res).Symbol self.S216=self.AddEquity('VRSN',res).Symbol self.S217=self.AddEquity('CIR',res).Symbol self.S218=self.AddEquity('MRCY',res).Symbol self.S219=self.AddEquity('ARWR',res).Symbol self.S220=self.AddEquity('SNAP',res).Symbol self.S221=self.AddEquity('ENPH',res).Symbol self.S222=self.AddEquity('MPW',res).Symbol self.S223=self.AddEquity('HI',res).Symbol self.S224=self.AddEquity('TTEK',res).Symbol self.S225=self.AddEquity('PI',res).Symbol self.S226=self.AddEquity('ADVM',res).Symbol self.S227=self.AddEquity('MSGS',res).Symbol self.S228=self.AddEquity('TGT',res).Symbol self.S229=self.AddEquity('ELF',res).Symbol self.S230=self.AddEquity('CTMX',res).Symbol self.S231=self.AddEquity('FCN',res).Symbol self.S232=self.AddEquity('FIT',res).Symbol self.S233=self.AddEquity('ANIK',res).Symbol self.S234=self.AddEquity('WGO',res).Symbol self.S235=self.AddEquity('CCXI',res).Symbol self.S236=self.AddEquity('TGTX',res).Symbol self.S237=self.AddEquity('MGI',res).Symbol self.S238=self.AddEquity('FCEL',res).Symbol self.S239=self.AddEquity('NVAX',res).Symbol self.S240=self.AddEquity('DOMO',res).Symbol self.S241=self.AddEquity('DELL',res).Symbol self.S242=self.AddEquity('GRPN',res).Symbol self.S243=self.AddEquity('DVAX',res).Symbol self.S244=self.AddEquity('WST',res).Symbol self.S245=self.AddEquity('TBIO',res).Symbol self.S246=self.AddEquity('INO',res).Symbol self.S247=self.AddEquity('MRSN',res).Symbol self.S248=self.AddEquity('TUP',res).Symbol self.S249=self.AddEquity('OMI',res).Symbol self.S250=self.AddEquity('FLDM',res).Symbol self.S251=self.AddEquity('JEF',res).Symbol self.S252=self.AddEquity('ALT',res).Symbol self.S253=self.AddEquity('MLHR',res).Symbol self.S254=self.AddEquity('CPK',res).Symbol self.S255=self.AddEquity('HOME',res).Symbol self.S256=self.AddEquity('SRRK',res).Symbol self.S257=self.AddEquity('EIDX',res).Symbol self.S258=self.AddEquity('WLL',res).Symbol self.S259=self.AddEquity('FUBO',res).Symbol self.S260=self.AddEquity('HDS',res).Symbol self.signals = {'2012-01-03':{self.S0:0.2,self.S1:0.2,self.S2:0.2,self.S3:0.2,self.S4:0.2},'2012-02-01':{self.S5:0.2,self.S6:0.2,self.S4:0.2,self.S7:0.2,self.S8:0.2},'2012-03-01':{self.S9:0.2,self.S10:0.2,self.S11:0.2,self.S6:0.2,self.S12:0.2},'2012-04-02':{self.S13:0.2,self.S14:0.2,self.S11:0.2,self.S6:0.2,self.S15:0.2},'2012-05-01':{self.S16:0.2,self.S17:0.2,self.S11:0.2,self.S8:0.2,self.S18:0.2},'2012-06-01':{self.S16:0.2,self.S19:0.2,self.S20:0.2,self.S21:0.2,self.S22:0.2},'2012-07-02':{self.S11:0.2,self.S16:0.2,self.S23:0.2,self.S24:0.2,self.S25:0.2},'2012-08-01':{self.S26:0.2,self.S16:0.2,self.S11:0.2,self.S27:0.2,self.S28:0.2},'2012-09-04':{self.S29:0.2,self.S30:0.2,self.S11:0.2,self.S17:0.2,self.S31:0.2},'2012-10-01':{self.S32:0.2,self.S30:0.2,self.S11:0.2,self.S17:0.2,self.S28:0.2},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S33:0.2,self.S16:0.2,self.S34:0.2,self.S4:0.2,self.S35:0.2},'2012-12-03':{self.S16:0.2,self.S36:0.2,self.S33:0.2,self.S37:0.2,self.S38:0.2},'2013-01-02':{self.S39:0.2,self.S40:0.2,self.S41:0.2,self.S4:0.2,self.S42:0.2},'2013-02-01':{self.S43:0.2,self.S40:0.2,self.S44:0.2,self.S45:0.2,self.S46:0.2},'2013-03-01':{self.S47:0.2,self.S48:0.2,self.S44:0.2,self.S40:0.2,self.S45:0.2},'2013-04-01':{self.S49:0.2,self.S50:0.2,self.S51:0.2,self.S52:0.2,self.S44:0.2},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S49:0.2,self.S53:0.2,self.S54:0.2,self.S45:0.2,self.S55:0.2},'2013-06-03':{self.S49:0.2,self.S53:0.2,self.S56:0.2,self.S54:0.2,self.S57:0.2},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S54:0.2,self.S58:0.2,self.S59:0.2,self.S60:0.2,self.S61:0.2},'2013-08-01':{self.S49:0.2,self.S62:0.2,self.S63:0.2,self.S54:0.2,self.S64:0.2},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S49:0.2,self.S65:0.2,self.S54:0.2,self.S66:0.2,self.S67:0.2},'2013-09-03':{self.S49:0.2,self.S54:0.2,self.S66:0.2,self.S65:0.2,self.S68:0.2},'2013-10-01':{self.S49:0.2,self.S59:0.2,self.S55:0.2,self.S54:0.2,self.S69:0.2},'2013-11-01':{self.S70:0.2,self.S71:0.2,self.S54:0.2,self.S72:0.2,self.S73:0.2},'2013-12-02':{self.S74:0.2,self.S75:0.2,self.S65:0.2,self.S76:0.2,self.S72:0.2},'2014-01-02':{self.S77:0.2,self.S78:0.2,self.S79:0.2,self.S55:0.2,self.S65:0.2},'2014-02-03':{self.S80:0.2,self.S81:0.2,self.S82:0.2,self.S83:0.2,self.S65:0.2},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S27:0.2,self.S84:0.2,self.S85:0.2,self.S86:0.2,self.S87:0.2},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S56:0.2,self.S84:0.2,self.S80:0.2,self.S27:0.2,self.S88:0.2},'2014-07-01':{self.S89:0.2,self.S90:0.2,self.S91:0.2,self.S88:0.2,self.S84:0.2},'2014-08-01':{self.S92:0.2,self.S84:0.2,self.S93:0.2,self.S88:0.2,self.S39:0.2},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S94:0.2,self.S95:0.2,self.S96:0.2,self.S23:0.2,self.S88:0.2},'2014-09-02':{self.S95:0.2,self.S94:0.2,self.S96:0.2,self.S97:0.2,self.S88:0.2},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S98:0.2,self.S99:0.2,self.S100:0.2,self.S9:0.2,self.S101:0.2},'2015-03-02':{self.S98:0.2,self.S101:0.2,self.S100:0.2,self.S102:0.2,self.S9:0.2},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S103:0.2,self.S104:0.2,self.S105:0.2,self.S106:0.2,self.S107:0.2},'2015-05-01':{self.S38:0.2,self.S106:0.2,self.S9:0.2,self.S104:0.2,self.S108:0.2},'2015-06-01':{self.S27:0.2,self.S106:0.2,self.S35:0.2,self.S109:0.2,self.S110:0.2},'2015-07-01':{self.S111:0.2,self.S27:0.2,self.S60:0.2,self.S9:0.2,self.S112:0.2},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S109:0.2,self.S113:0.2,self.S41:0.2,self.S114:0.2,self.S115:0.2},'2015-10-01':{self.S113:0.2,self.S109:0.2,self.S35:0.2,self.S114:0.2,self.S10:0.2},'2015-11-02':{self.S116:0.2,self.S9:0.2,self.S27:0.2,self.S35:0.2,self.S117:0.2},'2015-12-01':{self.S118:0.2,self.S116:0.2,self.S119:0.2,self.S9:0.2,self.S120:0.2},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S102:0.2,self.S121:0.2,self.S122:0.2,self.S123:0.2,self.S124:0.2},'2016-04-01':{self.S102:0.2,self.S123:0.2,self.S125:0.2,self.S126:0.2,self.S127:0.2},'2016-05-02':{self.S128:0.2,self.S129:0.2,self.S130:0.2,self.S131:0.2,self.S132:0.2},'2016-06-01':{self.S133:0.2,self.S128:0.2,self.S134:0.2,self.S135:0.2,self.S129:0.2},'2016-07-01':{self.S128:0.2,self.S136:0.2,self.S137:0.2,self.S129:0.2,self.S138:0.2},'2016-08-01':{self.S128:0.2,self.S139:0.2,self.S140:0.2,self.S129:0.2,self.S141:0.2},'2016-09-01':{self.S142:0.2,self.S128:0.2,self.S143:0.2,self.S139:0.2,self.S140:0.2},'2016-10-03':{self.S144:0.2,self.S145:0.2,self.S140:0.2,self.S139:0.2,self.S146:0.2},'2016-11-01':{self.S147:0.2,self.S148:0.2,self.S149:0.2,self.S150:0.2,self.S151:0.2},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S152:0.2,self.S153:0.2,self.S154:0.2,self.S155:0.2,self.S156:0.2},'2017-02-01':{self.S157:0.2,self.S41:0.2,self.S154:0.2,self.S158:0.2,self.S95:0.2},'2017-03-01':{self.S9:0.2,self.S68:0.2,self.S154:0.2,self.S159:0.2,self.S160:0.2},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S9:0.2,self.S155:0.2,self.S119:0.2,self.S161:0.2,self.S162:0.2},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S30:0.2,self.S163:0.2,self.S139:0.2,self.S164:0.2,self.S165:0.2},'2017-07-03':{self.S30:0.2,self.S92:0.2,self.S166:0.2,self.S167:0.2,self.S168:0.2},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S3:0.2,self.S30:0.2,self.S169:0.2,self.S170:0.2,self.S171:0.2},'2017-08-01':{self.S3:0.2,self.S30:0.2,self.S169:0.2,self.S172:0.2,self.S170:0.2},'2017-09-01':{self.S154:0.2,self.S169:0.2,self.S173:0.2,self.S174:0.2,self.S9:0.2},'2017-10-02':{self.S154:0.2,self.S175:0.2,self.S116:0.2,self.S176:0.2,self.S168:0.2},'2017-11-01':{self.S177:0.2,self.S168:0.2,self.S175:0.2,self.S176:0.2,self.S178:0.2},'2017-12-01':{self.S177:0.2,self.S179:0.2,self.S176:0.2,self.S175:0.2,self.S180:0.2},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S177:0.2,self.S176:0.2,self.S180:0.2,self.S36:0.2,self.S156:0.2},'2018-01-02':{self.S177:0.2,self.S176:0.2,self.S180:0.2,self.S36:0.2,self.S181:0.2},'2018-02-01':{self.S182:0.2,self.S176:0.2,self.S183:0.2,self.S184:0.2,self.S185:0.2},'2018-03-01':{self.S180:0.2,self.S186:0.2,self.S176:0.2,self.S183:0.2,self.S109:0.2},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S187:0.2,self.S188:0.2,self.S189:0.2,self.S190:0.2,self.S191:0.2},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S187:0.2,self.S188:0.2,self.S192:0.2,self.S193:0.2,self.S194:0.2},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S163:0.2,self.S195:0.2,self.S196:0.2,self.S197:0.2,self.S188:0.2},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S198:0.2,self.S199:0.2,self.S200:0.2,self.S201:0.2,self.S202:0.2},'2019-02-01':{self.S203:0.2,self.S200:0.2,self.S204:0.2,self.S205:0.2,self.S27:0.2},'2019-03-01':{self.S206:0.2,self.S207:0.2,self.S56:0.2,self.S208:0.2,self.S209:0.2},'2019-04-01':{self.S210:0.2,self.S211:0.2,self.S206:0.2,self.S207:0.2,self.S212:0.2},'2019-05-01':{self.S213:0.2,self.S214:0.2,self.S206:0.2,self.S215:0.2,self.S204:0.2},'2019-06-03':{self.S216:0.2,self.S217:0.2,self.S218:0.2,self.S219:0.2,self.S214:0.2},'2019-06-26':{self.TLT:1.0},'2019-07-29':{self.S220:0.2,self.S221:0.2,self.S222:0.2,self.S132:0.2,self.S223:0.2},'2019-08-01':{self.S224:0.2,self.S221:0.2,self.S220:0.2,self.S225:0.2,self.S82:0.2},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S126:0.2,self.S221:0.2,self.S226:0.2,self.S227:0.2,self.S228:0.2},'2019-09-03':{self.S221:0.2,self.S126:0.2,self.S123:0.2,self.S227:0.2,self.S229:0.2},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S230:0.2,self.S231:0.2,self.S232:0.2,self.S233:0.2,self.S93:0.2},'2019-11-01':{self.S230:0.2,self.S231:0.2,self.S232:0.2,self.S93:0.2,self.S234:0.2},'2019-12-02':{self.S126:0.2,self.S235:0.2,self.S236:0.2,self.S237:0.2,self.S230:0.2},'2020-01-02':{self.S55:0.2,self.S236:0.2,self.S235:0.2,self.S219:0.2,self.S30:0.2},'2020-02-03':{self.S230:0.2,self.S236:0.2,self.S238:0.2,self.S239:0.2,self.S235:0.2},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S240:0.2,self.S235:0.2,self.S241:0.2,self.S238:0.2,self.S242:0.2},'2020-05-01':{self.S242:0.2,self.S240:0.2,self.S238:0.2,self.S241:0.2,self.S235:0.2},'2020-06-01':{self.S239:0.2,self.S243:0.2,self.S244:0.2,self.S36:0.2,self.S240:0.2},'2020-07-01':{self.S245:0.2,self.S239:0.2,self.S246:0.2,self.S48:0.2,self.S247:0.2},'2020-08-03':{self.S239:0.2,self.S248:0.2,self.S249:0.2,self.S250:0.2,self.S177:0.2},'2020-09-01':{self.S177:0.2,self.S251:0.2,self.S250:0.2,self.S239:0.2,self.S252:0.2},'2020-10-01':{self.S177:0.2,self.S253:0.2,self.S254:0.2,self.S255:0.2,self.S248:0.2},'2020-11-02':{self.S251:0.2,self.S48:0.2,self.S256:0.2,self.S257:0.2,self.S258:0.2},'2020-12-01':{self.S48:0.2,self.S257:0.2,self.S259:0.2,self.S258:0.2,self.S260:0.2}} 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.90 * price)