Overall Statistics |
Total Trades 918 Average Win 1.91% Average Loss -2.06% Compounding Annual Return 26.919% Drawdown 44.500% Expectancy 0.214 Net Profit 756.788% Sharpe Ratio 1.053 Probabilistic Sharpe Ratio 39.128% Loss Rate 37% Win Rate 63% Profit-Loss Ratio 0.93 Alpha 0.119 Beta 0.88 Annual Standard Deviation 0.319 Annual Variance 0.102 Information Ratio 0.328 Tracking Error 0.271 Treynor Ratio 0.382 Total Fees $10610.16 |
import pandas as pd class LiquidUniverseSelection(QCAlgorithm): def Initialize(self): self.SetWarmup(10) self.SetBenchmark("QQQ") self.SetStartDate(2011, 12, 31) # self.SetEndDate(2014, 1, 1) self.cap =100000 self.SetCash(self.cap) 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('ALXN',res).Symbol self.S5=self.AddEquity('MTH',res).Symbol self.S6=self.AddEquity('URI',res).Symbol self.S7=self.AddEquity('MOH',res).Symbol self.S8=self.AddEquity('SNX',res).Symbol self.S9=self.AddEquity('SNBR',res).Symbol self.S10=self.AddEquity('TTC',res).Symbol self.S11=self.AddEquity('TWO',res).Symbol self.S12=self.AddEquity('LGF-A',res).Symbol self.S13=self.AddEquity('LNG',res).Symbol self.S14=self.AddEquity('ARNA',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('REGN',res).Symbol self.S21=self.AddEquity('AAL',res).Symbol self.S22=self.AddEquity('MNST',res).Symbol self.S23=self.AddEquity('LQDT',res).Symbol self.S24=self.AddEquity('DDD',res).Symbol self.S25=self.AddEquity('MGLN',res).Symbol self.S26=self.AddEquity('LL',res).Symbol self.S27=self.AddEquity('ALGN',res).Symbol self.S28=self.AddEquity('HAIN',res).Symbol self.S29=self.AddEquity('IMGN',res).Symbol self.S30=self.AddEquity('ADSK',res).Symbol self.S31=self.AddEquity('CQP',res).Symbol self.S32=self.AddEquity('SRPT',res).Symbol self.S33=self.AddEquity('COHR',res).Symbol self.S34=self.AddEquity('OPI',res).Symbol self.S35=self.AddEquity('GNRC',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('MDP',res).Symbol self.S41=self.AddEquity('CEQP',res).Symbol self.S42=self.AddEquity('CVI',res).Symbol self.S43=self.AddEquity('PPG',res).Symbol self.S44=self.AddEquity('NFLX',res).Symbol self.S45=self.AddEquity('UIS',res).Symbol self.S46=self.AddEquity('ODP',res).Symbol self.S47=self.AddEquity('EQC',res).Symbol self.S48=self.AddEquity('DK',res).Symbol self.S49=self.AddEquity('SVC',res).Symbol self.S50=self.AddEquity('RLJ',res).Symbol self.S51=self.AddEquity('ACAD',res).Symbol self.S52=self.AddEquity('VRTX',res).Symbol self.S53=self.AddEquity('SYNA',res).Symbol self.S54=self.AddEquity('SR',res).Symbol self.S55=self.AddEquity('SPWR',res).Symbol self.S56=self.AddEquity('DPZ',res).Symbol self.S57=self.AddEquity('TSLA',res).Symbol self.S58=self.AddEquity('RAD',res).Symbol self.S59=self.AddEquity('IRBT',res).Symbol self.S60=self.AddEquity('PFE',res).Symbol self.S61=self.AddEquity('TTEK',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('INCY',res).Symbol self.S68=self.AddEquity('HPQ',res).Symbol self.S69=self.AddEquity('CLDX',res).Symbol self.S70=self.AddEquity('AME',res).Symbol self.S71=self.AddEquity('AIR',res).Symbol self.S72=self.AddEquity('CVA',res).Symbol self.S73=self.AddEquity('SOL',res).Symbol self.S74=self.AddEquity('NTGR',res).Symbol self.S75=self.AddEquity('NHI',res).Symbol self.S76=self.AddEquity('GME',res).Symbol self.S77=self.AddEquity('TMUS',res).Symbol self.S78=self.AddEquity('YELP',res).Symbol self.S79=self.AddEquity('GIII',res).Symbol self.S80=self.AddEquity('CW',res).Symbol self.S81=self.AddEquity('UTHR',res).Symbol self.S82=self.AddEquity('IEP',res).Symbol self.S83=self.AddEquity('RXN',res).Symbol self.S84=self.AddEquity('TSCO',res).Symbol self.S85=self.AddEquity('ILMN',res).Symbol self.S86=self.AddEquity('VGR',res).Symbol self.S87=self.AddEquity('VZ',res).Symbol self.S88=self.AddEquity('CCOI',res).Symbol self.S89=self.AddEquity('IONS',res).Symbol self.S90=self.AddEquity('TTWO',res).Symbol self.S91=self.AddEquity('WWE',res).Symbol self.S92=self.AddEquity('MATX',res).Symbol self.S93=self.AddEquity('CHH',res).Symbol self.S94=self.AddEquity('AVNT',res).Symbol self.S95=self.AddEquity('SKX',res).Symbol self.S96=self.AddEquity('ZBRA',res).Symbol self.S97=self.AddEquity('UAA',res).Symbol self.S98=self.AddEquity('POWI',res).Symbol self.S99=self.AddEquity('DBI',res).Symbol self.S100=self.AddEquity('PEIX',res).Symbol self.S101=self.AddEquity('JOE',res).Symbol self.S102=self.AddEquity('PPC',res).Symbol self.S103=self.AddEquity('TRGP',res).Symbol self.S104=self.AddEquity('TCP',res).Symbol self.S105=self.AddEquity('REGI',res).Symbol self.S106=self.AddEquity('CENX',res).Symbol self.S107=self.AddEquity('SAFM',res).Symbol self.S108=self.AddEquity('WSM',res).Symbol self.S109=self.AddEquity('MED',res).Symbol self.S110=self.AddEquity('BBY',res).Symbol self.S111=self.AddEquity('UHS',res).Symbol self.S112=self.AddEquity('AMBA',res).Symbol self.S113=self.AddEquity('INFN',res).Symbol self.S114=self.AddEquity('KMI',res).Symbol self.S115=self.AddEquity('WGO',res).Symbol self.S116=self.AddEquity('STMP',res).Symbol self.S117=self.AddEquity('AAXN',res).Symbol self.S118=self.AddEquity('XPER',res).Symbol self.S119=self.AddEquity('SAM',res).Symbol self.S120=self.AddEquity('ABMD',res).Symbol self.S121=self.AddEquity('HA',res).Symbol self.S122=self.AddEquity('HCA',res).Symbol self.S123=self.AddEquity('DAN',res).Symbol self.S124=self.AddEquity('OSPN',res).Symbol self.S125=self.AddEquity('NDLS',res).Symbol self.S126=self.AddEquity('COLM',res).Symbol self.S127=self.AddEquity('GTN',res).Symbol self.S128=self.AddEquity('PGEN',res).Symbol self.S129=self.AddEquity('BLUE',res).Symbol self.S130=self.AddEquity('FOLD',res).Symbol self.S131=self.AddEquity('REX',res).Symbol self.S132=self.AddEquity('AZPN',res).Symbol self.S133=self.AddEquity('MEI',res).Symbol self.S134=self.AddEquity('SSNC',res).Symbol self.S135=self.AddEquity('NTCT',res).Symbol self.S136=self.AddEquity('CONN',res).Symbol self.S137=self.AddEquity('BLDR',res).Symbol self.S138=self.AddEquity('SUPN',res).Symbol self.S139=self.AddEquity('ITCI',res).Symbol self.S140=self.AddEquity('WW',res).Symbol self.S141=self.AddEquity('PINC',res).Symbol self.S142=self.AddEquity('ENTA',res).Symbol self.S143=self.AddEquity('BKH',res).Symbol self.S144=self.AddEquity('DXC',res).Symbol self.S145=self.AddEquity('GE',res).Symbol self.S146=self.AddEquity('CHD',res).Symbol self.S147=self.AddEquity('CPRT',res).Symbol self.S148=self.AddEquity('WCN',res).Symbol self.S149=self.AddEquity('FRT',res).Symbol self.S150=self.AddEquity('EPR',res).Symbol self.S151=self.AddEquity('GRPN',res).Symbol self.S152=self.AddEquity('FPRX',res).Symbol self.S153=self.AddEquity('TSE',res).Symbol self.S154=self.AddEquity('FR',res).Symbol self.S155=self.AddEquity('MIK',res).Symbol self.S156=self.AddEquity('CNC',res).Symbol self.S157=self.AddEquity('GLPI',res).Symbol self.S158=self.AddEquity('CPE',res).Symbol self.S159=self.AddEquity('IRM',res).Symbol self.S160=self.AddEquity('SAIA',res).Symbol self.S161=self.AddEquity('DLR',res).Symbol self.S162=self.AddEquity('LKQ',res).Symbol self.S163=self.AddEquity('MPW',res).Symbol self.S164=self.AddEquity('EVRG',res).Symbol self.S165=self.AddEquity('CDE',res).Symbol self.S166=self.AddEquity('SWX',res).Symbol self.S167=self.AddEquity('LNT',res).Symbol self.S168=self.AddEquity('MSGN',res).Symbol self.S169=self.AddEquity('EME',res).Symbol self.S170=self.AddEquity('SPB',res).Symbol self.S171=self.AddEquity('EXAS',res).Symbol self.S172=self.AddEquity('TVTY',res).Symbol self.S173=self.AddEquity('BDC',res).Symbol self.S174=self.AddEquity('GEO',res).Symbol self.S175=self.AddEquity('CXW',res).Symbol self.S176=self.AddEquity('COTY',res).Symbol self.S177=self.AddEquity('EXEL',res).Symbol self.S178=self.AddEquity('ET',res).Symbol self.S179=self.AddEquity('IART',res).Symbol self.S180=self.AddEquity('TTMI',res).Symbol self.S181=self.AddEquity('SXC',res).Symbol self.S182=self.AddEquity('VAR',res).Symbol self.S183=self.AddEquity('TMX',res).Symbol self.S184=self.AddEquity('LFUS',res).Symbol self.S185=self.AddEquity('VSAT',res).Symbol self.S186=self.AddEquity('PDCO',res).Symbol self.S187=self.AddEquity('NVDA',res).Symbol self.S188=self.AddEquity('NAV',res).Symbol self.S189=self.AddEquity('CSX',res).Symbol self.S190=self.AddEquity('MASI',res).Symbol self.S191=self.AddEquity('TRU',res).Symbol self.S192=self.AddEquity('OSUR',res).Symbol self.S193=self.AddEquity('CARA',res).Symbol self.S194=self.AddEquity('RYN',res).Symbol self.S195=self.AddEquity('SGMS',res).Symbol self.S196=self.AddEquity('ITGR',res).Symbol self.S197=self.AddEquity('JKHY',res).Symbol self.S198=self.AddEquity('HUN',res).Symbol self.S199=self.AddEquity('RRGB',res).Symbol self.S200=self.AddEquity('XENT',res).Symbol self.S201=self.AddEquity('NSA',res).Symbol self.S202=self.AddEquity('BLKB',res).Symbol self.S203=self.AddEquity('OMER',res).Symbol self.S204=self.AddEquity('PETS',res).Symbol self.S205=self.AddEquity('RMD',res).Symbol self.S206=self.AddEquity('AOS',res).Symbol self.S207=self.AddEquity('IQV',res).Symbol self.S208=self.AddEquity('TDW',res).Symbol self.S209=self.AddEquity('ZGNX',res).Symbol self.S210=self.AddEquity('SGMO',res).Symbol self.S211=self.AddEquity('OSTK',res).Symbol self.S212=self.AddEquity('CREE',res).Symbol self.S213=self.AddEquity('SQ',res).Symbol self.S214=self.AddEquity('RIOT',res).Symbol self.S215=self.AddEquity('NKTR',res).Symbol self.S216=self.AddEquity('WYNN',res).Symbol self.S217=self.AddEquity('AWR',res).Symbol self.S218=self.AddEquity('KDP',res).Symbol self.S219=self.AddEquity('FOSL',res).Symbol self.S220=self.AddEquity('CMD',res).Symbol self.S221=self.AddEquity('AROC',res).Symbol self.S222=self.AddEquity('SJI',res).Symbol self.S223=self.AddEquity('THC',res).Symbol self.S224=self.AddEquity('TNDM',res).Symbol self.S225=self.AddEquity('HEAR',res).Symbol self.S226=self.AddEquity('FLT',res).Symbol self.S227=self.AddEquity('PTCT',res).Symbol self.S228=self.AddEquity('BPT',res).Symbol self.S229=self.AddEquity('RETA',res).Symbol self.S230=self.AddEquity('IIIN',res).Symbol self.S231=self.AddEquity('SMCI',res).Symbol self.S232=self.AddEquity('AIMC',res).Symbol self.S233=self.AddEquity('FTV',res).Symbol self.S234=self.AddEquity('SXT',res).Symbol self.S235=self.AddEquity('ACHC',res).Symbol self.S236=self.AddEquity('LW',res).Symbol self.S237=self.AddEquity('SJW',res).Symbol self.S238=self.AddEquity('CACI',res).Symbol self.S239=self.AddEquity('RCII',res).Symbol self.S240=self.AddEquity('CDNA',res).Symbol self.S241=self.AddEquity('CSR',res).Symbol self.S242=self.AddEquity('TFX',res).Symbol self.S243=self.AddEquity('FISV',res).Symbol self.S244=self.AddEquity('XLNX',res).Symbol self.S245=self.AddEquity('BRC',res).Symbol self.S246=self.AddEquity('IIPR',res).Symbol self.S247=self.AddEquity('ATO',res).Symbol self.S248=self.AddEquity('LLY',res).Symbol self.S249=self.AddEquity('DBD',res).Symbol self.S250=self.AddEquity('LNTH',res).Symbol self.S251=self.AddEquity('WTRG',res).Symbol self.S252=self.AddEquity('VRSN',res).Symbol self.S253=self.AddEquity('QCOM',res).Symbol self.S254=self.AddEquity('LSCC',res).Symbol self.S255=self.AddEquity('ENPH',res).Symbol self.S256=self.AddEquity('BOOM',res).Symbol self.S257=self.AddEquity('MLAB',res).Symbol self.S258=self.AddEquity('SNAP',res).Symbol self.S259=self.AddEquity('PI',res).Symbol self.S260=self.AddEquity('VYGR',res).Symbol self.S261=self.AddEquity('LCI',res).Symbol self.S262=self.AddEquity('MSGS',res).Symbol self.S263=self.AddEquity('PSMT',res).Symbol self.S264=self.AddEquity('CDW',res).Symbol self.S265=self.AddEquity('HEP',res).Symbol self.S266=self.AddEquity('NVR',res).Symbol self.S267=self.AddEquity('FCN',res).Symbol self.S268=self.AddEquity('AMKR',res).Symbol self.S269=self.AddEquity('BIIB',res).Symbol self.S270=self.AddEquity('CCXI',res).Symbol self.S271=self.AddEquity('ANAB',res).Symbol self.S272=self.AddEquity('RH',res).Symbol self.S273=self.AddEquity('TGTX',res).Symbol self.S274=self.AddEquity('ARWR',res).Symbol self.S275=self.AddEquity('XLRN',res).Symbol self.S276=self.AddEquity('CBB',res).Symbol self.S277=self.AddEquity('CODX',res).Symbol self.S278=self.AddEquity('APRN',res).Symbol self.S279=self.AddEquity('INO',res).Symbol self.S280=self.AddEquity('DOMO',res).Symbol self.S281=self.AddEquity('LPI',res).Symbol self.S282=self.AddEquity('WST',res).Symbol self.S283=self.AddEquity('NVAX',res).Symbol self.S284=self.AddEquity('ECL',res).Symbol self.S285=self.AddEquity('WKHS',res).Symbol self.S286=self.AddEquity('RMED',res).Symbol self.S287=self.AddEquity('MRSN',res).Symbol self.S288=self.AddEquity('KODK',res).Symbol self.S289=self.AddEquity('UONE',res).Symbol self.S290=self.AddEquity('GRWG',res).Symbol self.S291=self.AddEquity('ALT',res).Symbol self.S292=self.AddEquity('MLHR',res).Symbol self.S293=self.AddEquity('HOME',res).Symbol self.S294=self.AddEquity('CPK',res).Symbol self.S295=self.AddEquity('TUP',res).Symbol self.S296=self.AddEquity('SRRK',res).Symbol self.S297=self.AddEquity('EIDX',res).Symbol self.S298=self.AddEquity('WLL',res).Symbol self.S299=self.AddEquity('FCEL',res).Symbol self.S300=self.AddEquity('BLNK',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.S7:0.2,self.S8:0.2,self.S9:0.2},'2012-03-01':{self.S7:0.2,self.S10:0.2,self.S6:0.2,self.S8:0.2,self.S11:0.2},'2012-04-02':{self.S12:0.2,self.S13:0.2,self.S14:0.2,self.S6:0.2,self.S15:0.2},'2012-05-01':{self.S16:0.2,self.S17:0.2,self.S14:0.2,self.S9:0.2,self.S18:0.2},'2012-06-01':{self.S19:0.2,self.S4:0.2,self.S16:0.2,self.S20:0.2,self.S21:0.2},'2012-07-02':{self.S14:0.2,self.S16:0.2,self.S22:0.2,self.S23:0.2,self.S24:0.2},'2012-08-01':{self.S25:0.2,self.S16:0.2,self.S14:0.2,self.S26:0.2,self.S27:0.2},'2012-09-04':{self.S28:0.2,self.S29:0.2,self.S14:0.2,self.S17:0.2,self.S30:0.2},'2012-10-01':{self.S31:0.2,self.S29:0.2,self.S8:0.2,self.S14:0.2,self.S17:0.2},'2012-11-01':{self.S32:0.2,self.S16:0.2,self.S33:0.2,self.S34:0.2,self.S35:0.2},'2012-12-03':{self.S36:0.2,self.S16:0.2,self.S35:0.2,self.S37:0.2,self.S38:0.2},'2013-01-02':{self.S39:0.2,self.S8:0.2,self.S40:0.2,self.S41:0.2,self.S42:0.2},'2013-02-01':{self.S43:0.2,self.S44:0.2,self.S42:0.2,self.S24:0.2,self.S45:0.2},'2013-03-01':{self.S46:0.2,self.S47:0.2,self.S44:0.2,self.S42:0.2,self.S8:0.2},'2013-04-01':{self.S48:0.2,self.S49:0.2,self.S50:0.2,self.S44:0.2,self.S8:0.2},'2013-05-01':{self.S51:0.2,self.S52:0.2,self.S45:0.2,self.S8:0.2,self.S53:0.2},'2013-06-03':{self.S54:0.2,self.S55:0.2,self.S56:0.2,self.S57:0.2,self.S58:0.2},'2013-07-01':{self.S59:0.2,self.S60:0.2,self.S8:0.2,self.S58:0.2,self.S61:0.2},'2013-08-01':{self.S62:0.2,self.S63:0.2,self.S39:0.2,self.S64:0.2,self.S57:0.2},'2013-09-03':{self.S57:0.2,self.S65:0.2,self.S66:0.2,self.S67:0.2,self.S68:0.2},'2013-10-01':{self.S58:0.2,self.S69:0.2,self.S70:0.2,self.S57:0.2,self.S71:0.2},'2013-11-01':{self.S72:0.2,self.S73:0.2,self.S74:0.2,self.S57:0.2,self.S8:0.2},'2013-12-02':{self.S75:0.2,self.S65:0.2,self.S76:0.2,self.S77:0.2,self.S78:0.2},'2014-01-02':{self.S79:0.2,self.S80:0.2,self.S81:0.2,self.S82:0.2,self.S65:0.2},'2014-02-03':{self.S83:0.2,self.S84:0.2,self.S85:0.2,self.S65:0.2,self.S86:0.2},'2014-03-03':{self.S87:0.2,self.S88:0.2,self.S85:0.2,self.S89:0.2,self.S90:0.2},'2014-04-01':{self.S91:0.2,self.S92:0.2,self.S93:0.2,self.S85:0.2,self.S68:0.2},'2014-05-01':{self.S94:0.2,self.S95:0.2,self.S96:0.2,self.S97:0.2,self.S98:0.2},'2014-06-02':{self.S99:0.2,self.S100:0.2,self.S101:0.2,self.S83:0.2,self.S102:0.2},'2014-07-01':{self.S103:0.2,self.S101:0.2,self.S104:0.2,self.S100:0.2,self.S102:0.2},'2014-08-01':{self.S34:0.2,self.S100:0.2,self.S105:0.2,self.S102:0.2,self.S7:0.2},'2014-09-02':{self.S106:0.2,self.S107:0.2,self.S108:0.2,self.S109:0.2,self.S110:0.2},'2014-10-01':{self.S37:0.2,self.S95:0.2,self.S111:0.2,self.S106:0.2,self.S112:0.2},'2014-11-03':{self.S113:0.2,self.S90:0.2,self.S62:0.2,self.S9:0.2,self.S7:0.2},'2014-12-01':{self.S104:0.2,self.S106:0.2,self.S114:0.2,self.S7:0.2,self.S90:0.2},'2015-01-02':{self.S89:0.2,self.S115:0.2,self.S116:0.2,self.S117:0.2,self.S118:0.2},'2015-02-02':{self.S119:0.2,self.S120:0.2,self.S121:0.2,self.S122:0.2,self.S123:0.2},'2015-03-02':{self.S124:0.2,self.S125:0.2,self.S126:0.2,self.S7:0.2,self.S119:0.2},'2015-04-01':{self.S127:0.2,self.S120:0.2,self.S128:0.2,self.S129:0.2,self.S130:0.2},'2015-05-01':{self.S38:0.2,self.S129:0.2,self.S7:0.2,self.S120:0.2,self.S74:0.2},'2015-06-01':{self.S129:0.2,self.S7:0.2,self.S131:0.2,self.S37:0.2,self.S132:0.2},'2015-07-01':{self.S112:0.2,self.S7:0.2,self.S133:0.2,self.S134:0.2,self.S95:0.2},'2015-08-03':{self.S135:0.2,self.S136:0.2,self.S95:0.2,self.S132:0.2,self.S131:0.2},'2015-09-01':{self.S132:0.2,self.S137:0.2,self.S95:0.2,self.S7:0.2,self.S138:0.2},'2015-10-01':{self.S132:0.2,self.S139:0.2,self.S10:0.2,self.S137:0.2,self.S7:0.2},'2015-11-02':{self.S140:0.2,self.S7:0.2,self.S141:0.2,self.S142:0.2,self.S131:0.2},'2015-12-01':{self.S143:0.2,self.S140:0.2,self.S7:0.2,self.S144:0.2,self.S145:0.2},'2016-01-04':{self.S140:0.2,self.S146:0.2,self.S8:0.2,self.S7:0.2,self.S147:0.2},'2016-02-01':{self.S132:0.2,self.S148:0.2,self.S149:0.2,self.S140:0.2,self.S150:0.2},'2016-03-01':{self.S132:0.2,self.S140:0.2,self.S88:0.2,self.S151:0.2,self.S121:0.2},'2016-04-01':{self.S152:0.2,self.S153:0.2,self.S154:0.2,self.S155:0.2,self.S156:0.2},'2016-05-02':{self.S157:0.2,self.S158:0.2,self.S159:0.2,self.S160:0.2,self.S32:0.2},'2016-06-01':{self.S161:0.2,self.S162:0.2,self.S148:0.2,self.S163:0.2,self.S164:0.2},'2016-07-01':{self.S165:0.2,self.S166:0.2,self.S167:0.2,self.S168:0.2,self.S169:0.2},'2016-08-01':{self.S170:0.2,self.S165:0.2,self.S171:0.2,self.S172:0.2,self.S173:0.2},'2016-09-01':{self.S170:0.2,self.S174:0.2,self.S165:0.2,self.S175:0.2,self.S171:0.2},'2016-10-03':{self.S170:0.2,self.S176:0.2,self.S177:0.2,self.S178:0.2,self.S172:0.2},'2016-11-01':{self.S170:0.2,self.S179:0.2,self.S180:0.2,self.S181:0.2,self.S182:0.2},'2016-12-01':{self.S183:0.2,self.S180:0.2,self.S184:0.2,self.S185:0.2,self.S186:0.2},'2017-01-03':{self.S187:0.2,self.S183:0.2,self.S188:0.2,self.S140:0.2,self.S115:0.2},'2017-02-01':{self.S170:0.2,self.S189:0.2,self.S183:0.2,self.S106:0.2,self.S40:0.2},'2017-03-01':{self.S7:0.2,self.S67:0.2,self.S183:0.2,self.S190:0.2,self.S191:0.2},'2017-04-03':{self.S192:0.2,self.S36:0.2,self.S193:0.2,self.S194:0.2,self.S195:0.2},'2017-05-01':{self.S7:0.2,self.S9:0.2,self.S196:0.2,self.S193:0.2,self.S175:0.2},'2017-06-01':{self.S197:0.2,self.S198:0.2,self.S199:0.2,self.S83:0.2,self.S200:0.2},'2017-07-03':{self.S34:0.2,self.S201:0.2,self.S202:0.2,self.S203:0.2,self.S7:0.2},'2017-08-01':{self.S3:0.2,self.S204:0.2,self.S205:0.2,self.S195:0.2,self.S206:0.2},'2017-09-01':{self.S183:0.2,self.S204:0.2,self.S207:0.2,self.S136:0.2,self.S7:0.2},'2017-10-02':{self.S208:0.2,self.S183:0.2,self.S209:0.2,self.S140:0.2,self.S210:0.2},'2017-11-01':{self.S211:0.2,self.S208:0.2,self.S210:0.2,self.S209:0.2,self.S212:0.2},'2017-12-01':{self.S211:0.2,self.S208:0.2,self.S213:0.2,self.S209:0.2,self.S7:0.2},'2018-01-02':{self.S214:0.2,self.S208:0.2,self.S211:0.2,self.S7:0.2,self.S215:0.2},'2018-02-01':{self.S208:0.2,self.S216:0.2,self.S214:0.2,self.S217:0.2,self.S218:0.2},'2018-03-01':{self.S215:0.2,self.S219:0.2,self.S208:0.2,self.S132:0.2,self.S214:0.2},'2018-04-02':{self.S215:0.2,self.S14:0.2,self.S220:0.2,self.S132:0.2,self.S209:0.2},'2018-05-01':{self.S69:0.2,self.S215:0.2,self.S221:0.2,self.S222:0.2,self.S95:0.2},'2018-06-01':{self.S120:0.2,self.S91:0.2,self.S223:0.2,self.S117:0.2,self.S62:0.2},'2018-07-02':{self.S224:0.2,self.S225:0.2,self.S226:0.2,self.S227:0.2,self.S147:0.2},'2018-08-01':{self.S225:0.2,self.S228:0.2,self.S229:0.2,self.S224:0.2,self.S230:0.2},'2018-09-04':{self.S225:0.2,self.S228:0.2,self.S231:0.2,self.S224:0.2,self.S45:0.2},'2018-10-01':{self.S228:0.2,self.S224:0.2,self.S225:0.2,self.S232:0.2,self.S233:0.2},'2018-11-01':{self.S228:0.2,self.S234:0.2,self.S235:0.2,self.S224:0.2,self.S178:0.2},'2018-12-03':{self.S228:0.2,self.S236:0.2,self.S237:0.2,self.S238:0.2,self.S105:0.2},'2019-01-02':{self.S228:0.2,self.S239:0.2,self.S240:0.2,self.S241:0.2,self.S105:0.2},'2019-02-01':{self.S242:0.2,self.S243:0.2,self.S228:0.2,self.S244:0.2,self.S245:0.2},'2019-03-01':{self.S246:0.2,self.S54:0.2,self.S247:0.2,self.S248:0.2,self.S228:0.2},'2019-04-01':{self.S228:0.2,self.S249:0.2,self.S246:0.2,self.S250:0.2,self.S118:0.2},'2019-05-01':{self.S251:0.2,self.S252:0.2,self.S249:0.2,self.S228:0.2,self.S253:0.2},'2019-06-03':{self.S252:0.2,self.S228:0.2,self.S254:0.2,self.S255:0.2,self.S256:0.2},'2019-07-01':{self.S252:0.2,self.S241:0.2,self.S255:0.2,self.S228:0.2,self.S257:0.2},'2019-08-01':{self.S61:0.2,self.S255:0.2,self.S258:0.2,self.S259:0.2,self.S260:0.2},'2019-09-03':{self.S255:0.2,self.S241:0.2,self.S153:0.2,self.S261:0.2,self.S262:0.2},'2019-10-01':{self.S263:0.2,self.S264:0.2,self.S255:0.2,self.S265:0.2,self.S266:0.2},'2019-11-01':{self.S267:0.2,self.S268:0.2,self.S204:0.2,self.S115:0.2,self.S269:0.2},'2019-12-02':{self.S229:0.2,self.S116:0.2,self.S270:0.2,self.S271:0.2,self.S272:0.2},'2020-01-02':{self.S271:0.2,self.S58:0.2,self.S273:0.2,self.S270:0.2,self.S274:0.2},'2020-02-03':{self.S273:0.2,self.S271:0.2,self.S275:0.2,self.S270:0.2,self.S276:0.2},'2020-03-02':{self.S277:0.2,self.S273:0.2,self.S270:0.2,self.S271:0.2,self.S57:0.2},'2020-04-01':{self.S271:0.2,self.S270:0.2,self.S278:0.2,self.S276:0.2,self.S57:0.2},'2020-05-01':{self.S277:0.2,self.S151:0.2,self.S279:0.2,self.S280:0.2,self.S281:0.2},'2020-06-01':{self.S277:0.2,self.S282:0.2,self.S283:0.2,self.S36:0.2,self.S284:0.2},'2020-07-01':{self.S285:0.2,self.S286:0.2,self.S277:0.2,self.S283:0.2,self.S287:0.2},'2020-08-03':{self.S288:0.2,self.S283:0.2,self.S289:0.2,self.S285:0.2,self.S47:0.2},'2020-09-01':{self.S290:0.2,self.S211:0.2,self.S283:0.2,self.S291:0.2,self.S47:0.2},'2020-10-01':{self.S211:0.2,self.S292:0.2,self.S293:0.2,self.S294:0.2,self.S295:0.2},'2020-11-02':{self.S47:0.2,self.S296:0.2,self.S297:0.2,self.S298:0.2,self.S295:0.2},'2020-12-01':{self.S47:0.2,self.S297:0.2,self.S299:0.2,self.S298:0.2,self.S300: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 self.Transactions.CancelOpenOrders() 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(): # quantity = self.CalculateOrderQuantity(sec, weight) # self.LimitOrder(sec, quantity, self.Securities[sec].Price) self.SetHoldings(sec, weight) # quantity = self.CalculateOrderQuantity(sec, weight) # self.LimitOrder(sec, int(quantity*1.05), self.Securities[sec].Price*0.95) # quantity = self.CalculateOrderQuantity(sec, weight/3) # self.LimitOrder(sec, int(quantity*1.1), self.Securities[sec].Price*0.90) # 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.80 * price)