Overall Statistics |
Total Trades 700 Average Win 1.88% Average Loss -1.45% Compounding Annual Return 24.706% Drawdown 45.900% Expectancy 0.397 Net Profit 630.334% Sharpe Ratio 1.129 Probabilistic Sharpe Ratio 49.067% Loss Rate 39% Win Rate 61% Profit-Loss Ratio 1.29 Alpha 0.248 Beta 0.156 Annual Standard Deviation 0.254 Annual Variance 0.064 Information Ratio 0.133 Tracking Error 0.299 Treynor Ratio 1.829 Total Fees $9719.87 |
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('URI',res).Symbol self.S1=self.AddEquity('SBAC',res).Symbol self.S2=self.AddEquity('TREE',res).Symbol self.S3=self.AddEquity('NAV',res).Symbol self.S4=self.AddEquity('AGX',res).Symbol self.S5=self.AddEquity('CIEN',res).Symbol self.S6=self.AddEquity('DJCO',res).Symbol self.S7=self.AddEquity('IEP',res).Symbol self.S8=self.AddEquity('CHTR',res).Symbol self.S9=self.AddEquity('VNDA',res).Symbol self.S10=self.AddEquity('CCK',res).Symbol self.S11=self.AddEquity('PM',res).Symbol self.S12=self.AddEquity('CELH',res).Symbol self.S13=self.AddEquity('DISH',res).Symbol self.S14=self.AddEquity('IMGN',res).Symbol self.S15=self.AddEquity('SBR',res).Symbol self.S16=self.AddEquity('WKHS',res).Symbol self.S17=self.AddEquity('DENN',res).Symbol self.S18=self.AddEquity('EVI',res).Symbol self.S19=self.AddEquity('MSB',res).Symbol self.S20=self.AddEquity('LMT',res).Symbol self.S21=self.AddEquity('WYNN',res).Symbol self.S22=self.AddEquity('NXST',res).Symbol self.S23=self.AddEquity('RDNT',res).Symbol self.S24=self.AddEquity('OMER',res).Symbol self.S25=self.AddEquity('UAL',res).Symbol self.S26=self.AddEquity('PBI',res).Symbol self.S27=self.AddEquity('WD',res).Symbol self.S28=self.AddEquity('GDOT',res).Symbol self.S29=self.AddEquity('CWST',res).Symbol self.S30=self.AddEquity('FUN',res).Symbol self.S31=self.AddEquity('HLF',res).Symbol self.S32=self.AddEquity('PRTK',res).Symbol self.S33=self.AddEquity('TTWO',res).Symbol self.S34=self.AddEquity('EAT',res).Symbol self.S35=self.AddEquity('LB',res).Symbol self.S36=self.AddEquity('SGMS',res).Symbol self.S37=self.AddEquity('MGI',res).Symbol self.S38=self.AddEquity('BLNK',res).Symbol self.S39=self.AddEquity('MOH',res).Symbol self.S40=self.AddEquity('AMD',res).Symbol self.S41=self.AddEquity('SNEX',res).Symbol self.S42=self.AddEquity('SGU',res).Symbol self.S43=self.AddEquity('IDXX',res).Symbol self.S44=self.AddEquity('AZPN',res).Symbol self.S45=self.AddEquity('MAS',res).Symbol self.S46=self.AddEquity('CCOI',res).Symbol self.S47=self.AddEquity('FPRX',res).Symbol self.S48=self.AddEquity('SIGA',res).Symbol self.S49=self.AddEquity('INS',res).Symbol self.S50=self.AddEquity('RYAM',res).Symbol self.S51=self.AddEquity('BERY',res).Symbol self.S52=self.AddEquity('HRB',res).Symbol self.S53=self.AddEquity('MC',res).Symbol self.S54=self.AddEquity('CQP',res).Symbol self.S55=self.AddEquity('KOP',res).Symbol self.S56=self.AddEquity('CL',res).Symbol self.S57=self.AddEquity('KMB',res).Symbol self.S58=self.AddEquity('SSYS',res).Symbol self.S59=self.AddEquity('RILY',res).Symbol self.S60=self.AddEquity('GLIBA',res).Symbol self.S61=self.AddEquity('GBX',res).Symbol self.S62=self.AddEquity('ENVA',res).Symbol self.S63=self.AddEquity('BA',res).Symbol self.S64=self.AddEquity('ADVM',res).Symbol self.S65=self.AddEquity('LII',res).Symbol self.S66=self.AddEquity('TPX',res).Symbol self.S67=self.AddEquity('CAR',res).Symbol self.S68=self.AddEquity('VXRT',res).Symbol self.S69=self.AddEquity('CDK',res).Symbol self.S70=self.AddEquity('W',res).Symbol self.S71=self.AddEquity('AMCX',res).Symbol self.S72=self.AddEquity('IRWD',res).Symbol self.S73=self.AddEquity('ENR',res).Symbol self.S74=self.AddEquity('RH',res).Symbol self.S75=self.AddEquity('CNCE',res).Symbol self.S76=self.AddEquity('GBL',res).Symbol self.S77=self.AddEquity('OTRK',res).Symbol self.S78=self.AddEquity('RYI',res).Symbol self.S79=self.AddEquity('PENN',res).Symbol self.S80=self.AddEquity('CAPL',res).Symbol self.S81=self.AddEquity('REGI',res).Symbol self.S82=self.AddEquity('VRS',res).Symbol self.S83=self.AddEquity('DELL',res).Symbol self.S84=self.AddEquity('OPY',res).Symbol self.S85=self.AddEquity('VRSN',res).Symbol self.S86=self.AddEquity('ARNA',res).Symbol self.S87=self.AddEquity('HCC',res).Symbol self.S88=self.AddEquity('TGTX',res).Symbol self.S89=self.AddEquity('AAL',res).Symbol self.S90=self.AddEquity('CLDX',res).Symbol self.S91=self.AddEquity('SBH',res).Symbol self.S92=self.AddEquity('CRIS',res).Symbol self.S93=self.AddEquity('DOMO',res).Symbol self.S94=self.AddEquity('MVIS',res).Symbol self.S95=self.AddEquity('NLOK',res).Symbol self.S96=self.AddEquity('VHC',res).Symbol self.S97=self.AddEquity('TVTY',res).Symbol self.S98=self.AddEquity('JEF',res).Symbol self.S99=self.AddEquity('SEAS',res).Symbol self.S100=self.AddEquity('OI',res).Symbol self.S101=self.AddEquity('AWH',res).Symbol self.S102=self.AddEquity('EIDX',res).Symbol self.S103=self.AddEquity('SEE',res).Symbol self.S104=self.AddEquity('BLMN',res).Symbol self.S105=self.AddEquity('WU',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.S1:0.2,self.S2:0.2,self.S3:0.2,self.S4:0.2,self.S5:0.2},'2012-03-01':{self.S2:0.2,self.S1:0.2,self.S4:0.2,self.S6:0.2,self.S7:0.2},'2012-04-02':{self.S2:0.2,self.S1:0.2,self.S4:0.2,self.S6:0.2,self.S7:0.2},'2012-05-01':{self.S2:0.2,self.S4:0.2,self.S0:0.2,self.S8:0.2,self.S6:0.2},'2012-06-01':{self.S2:0.2,self.S6:0.2,self.S0:0.2,self.S4:0.2,self.S8:0.2},'2012-07-02':{self.S2:0.2,self.S0:0.2,self.S4:0.2,self.S8:0.2,self.S6:0.2},'2012-08-01':{self.S9:0.2,self.S10:0.2,self.S11:0.2,self.S2:0.2,self.S12:0.2},'2012-09-04':{self.S10:0.2,self.S4:0.2,self.S11:0.2,self.S13:0.2,self.S14:0.2},'2012-10-01':{self.S10:0.2,self.S14:0.2,self.S4:0.2,self.S15:0.2,self.S16:0.2},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S4:0.2,self.S17:0.2,self.S2:0.2,self.S11:0.2,self.S15:0.2},'2012-12-03':{self.S18:0.2,self.S17:0.2,self.S4:0.2,self.S15:0.2,self.S11:0.2},'2013-01-02':{self.S17:0.2,self.S4:0.2,self.S18:0.2,self.S11:0.2,self.S19:0.2},'2013-02-01':{self.S9:0.2,self.S17:0.2,self.S20:0.2,self.S11:0.2,self.S8:0.2},'2013-03-01':{self.S20:0.2,self.S13:0.2,self.S4:0.2,self.S8:0.2,self.S21:0.2},'2013-04-01':{self.S22:0.2,self.S4:0.2,self.S20:0.2,self.S13:0.2,self.S2:0.2},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S22:0.2,self.S23:0.2,self.S24:0.2,self.S25:0.2,self.S8:0.2},'2013-06-03':{self.S22:0.2,self.S23:0.2,self.S24:0.2,self.S25:0.2,self.S8:0.2},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S24:0.2,self.S22:0.2,self.S23:0.2,self.S25:0.2,self.S8:0.2},'2013-08-01':{self.S22:0.2,self.S24:0.2,self.S23:0.2,self.S26:0.2,self.S2:0.2},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S8:0.2,self.S22:0.2,self.S26:0.2,self.S19:0.2,self.S23:0.2},'2013-09-03':{self.S8:0.2,self.S22:0.2,self.S26:0.2,self.S23:0.2,self.S19:0.2},'2013-10-01':{self.S8:0.2,self.S19:0.2,self.S22:0.2,self.S26:0.2,self.S23:0.2},'2013-11-01':{self.S17:0.2,self.S19:0.2,self.S26:0.2,self.S8:0.2,self.S22:0.2},'2013-12-02':{self.S23:0.2,self.S18:0.2,self.S17:0.2,self.S19:0.2,self.S27:0.2},'2014-01-02':{self.S23:0.2,self.S18:0.2,self.S4:0.2,self.S17:0.2,self.S27:0.2},'2014-02-03':{self.S23:0.2,self.S18:0.2,self.S4:0.2,self.S17:0.2,self.S27:0.2},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S23:0.2,self.S4:0.2,self.S19:0.2,self.S28:0.2,self.S8:0.2},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S4:0.2,self.S19:0.2,self.S8:0.2,self.S29:0.2,self.S30:0.2},'2014-07-01':{self.S19:0.2,self.S8:0.2,self.S30:0.2,self.S4:0.2,self.S31:0.2},'2014-08-01':{self.S32:0.2,self.S19:0.2,self.S4:0.2,self.S14:0.2,self.S15:0.2},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S4:0.2,self.S19:0.2,self.S28:0.2,self.S9:0.2,self.S33:0.2},'2014-09-02':{self.S4:0.2,self.S19:0.2,self.S28:0.2,self.S9:0.2,self.S33:0.2},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S32:0.2,self.S23:0.2,self.S34:0.2,self.S8:0.2,self.S17:0.2},'2015-03-02':{self.S32:0.2,self.S35:0.2,self.S23:0.2,self.S34:0.2,self.S8:0.2},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S36:0.2,self.S37:0.2,self.S38:0.2,self.S4:0.2,self.S39:0.2},'2015-05-01':{self.S37:0.2,self.S36:0.2,self.S38:0.2,self.S4:0.2,self.S39:0.2},'2015-06-01':{self.S39:0.2,self.S8:0.2,self.S38:0.2,self.S40:0.2,self.S4:0.2},'2015-07-01':{self.S38:0.2,self.S37:0.2,self.S39:0.2,self.S8:0.2,self.S40:0.2},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S38:0.2,self.S39:0.2,self.S41:0.2,self.S42:0.2,self.S43:0.2},'2015-10-01':{self.S44:0.2,self.S39:0.2,self.S43:0.2,self.S17:0.2,self.S41:0.2},'2015-11-02':{self.S37:0.2,self.S8:0.2,self.S39:0.2,self.S15:0.2,self.S45:0.2},'2015-12-01':{self.S8:0.2,self.S46:0.2,self.S37:0.2,self.S39:0.2,self.S45:0.2},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S47:0.2,self.S48:0.2,self.S39:0.2,self.S21:0.2,self.S28:0.2},'2016-04-01':{self.S47:0.2,self.S48:0.2,self.S39:0.2,self.S21:0.2,self.S28:0.2},'2016-05-02':{self.S47:0.2,self.S21:0.2,self.S48:0.2,self.S39:0.2,self.S28:0.2},'2016-06-01':{self.S49:0.2,self.S48:0.2,self.S47:0.2,self.S50:0.2,self.S39:0.2},'2016-07-01':{self.S50:0.2,self.S21:0.2,self.S51:0.2,self.S52:0.2,self.S45:0.2},'2016-08-01':{self.S21:0.2,self.S47:0.2,self.S48:0.2,self.S39:0.2,self.S27:0.2},'2016-09-01':{self.S21:0.2,self.S48:0.2,self.S47:0.2,self.S39:0.2,self.S53:0.2},'2016-10-03':{self.S21:0.2,self.S48:0.2,self.S47:0.2,self.S4:0.2,self.S39:0.2},'2016-11-01':{self.S21:0.2,self.S48:0.2,self.S39:0.2,self.S47:0.2,self.S4:0.2},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S45:0.2,self.S54:0.2,self.S51:0.2,self.S55:0.2,self.S56:0.2},'2017-02-01':{self.S56:0.2,self.S39:0.2,self.S57:0.2,self.S4:0.2,self.S58:0.2},'2017-03-01':{self.S56:0.2,self.S39:0.2,self.S53:0.2,self.S4:0.2,self.S58:0.2},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S39:0.2,self.S4:0.2,self.S53:0.2,self.S59:0.2,self.S56:0.2},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S39:0.2,self.S4:0.2,self.S60:0.2,self.S61:0.2,self.S53:0.2},'2017-07-03':{self.S39:0.2,self.S4:0.2,self.S62:0.2,self.S63:0.2,self.S53:0.2},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S64:0.2,self.S26:0.2,self.S65:0.2,self.S66:0.2,self.S67:0.2},'2017-08-01':{self.S64:0.2,self.S39:0.2,self.S65:0.2,self.S66:0.2,self.S67:0.2},'2017-09-01':{self.S68:0.2,self.S67:0.2,self.S26:0.2,self.S65:0.2,self.S66:0.2},'2017-10-02':{self.S68:0.2,self.S67:0.2,self.S26:0.2,self.S65:0.2,self.S66:0.2},'2017-11-01':{self.S68:0.2,self.S69:0.2,self.S39:0.2,self.S64:0.2,self.S26:0.2},'2017-12-01':{self.S68:0.2,self.S69:0.2,self.S70:0.2,self.S39:0.2,self.S64:0.2},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S68:0.2,self.S69:0.2,self.S39:0.2,self.S70:0.2,self.S64:0.2},'2018-01-02':{self.S68:0.2,self.S69:0.2,self.S39:0.2,self.S70:0.2,self.S64:0.2},'2018-02-01':{self.S68:0.2,self.S70:0.2,self.S39:0.2,self.S64:0.2,self.S45:0.2},'2018-03-01':{self.S68:0.2,self.S64:0.2,self.S71:0.2,self.S72:0.2,self.S73:0.2},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S39:0.2,self.S74:0.2,self.S15:0.2,self.S75:0.2,self.S76:0.2},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S77:0.2,self.S78:0.2,self.S15:0.2,self.S79:0.2,self.S67:0.2},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S48:0.2,self.S80:0.2,self.S81:0.2,self.S76:0.2,self.S82:0.2},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S48:0.2,self.S80:0.2,self.S81:0.2,self.S76:0.2,self.S82:0.2},'2019-02-01':{self.S48:0.2,self.S80:0.2,self.S81:0.2,self.S76:0.2,self.S62:0.2},'2019-03-01':{self.S83:0.2,self.S48:0.2,self.S81:0.2,self.S84:0.2,self.S62:0.2},'2019-04-01':{self.S83:0.2,self.S48:0.2,self.S81:0.2,self.S84:0.2,self.S62:0.2},'2019-05-01':{self.S83:0.2,self.S48:0.2,self.S45:0.2,self.S81:0.2,self.S62:0.2},'2019-06-03':{self.S85:0.2,self.S83:0.2,self.S86:0.2,self.S48:0.2,self.S62:0.2},'2019-06-26':{self.TLT:1.0},'2019-07-29':{self.S48:0.2,self.S86:0.2,self.S83:0.2,self.S62:0.2,self.S87:0.2},'2019-08-01':{self.S48:0.2,self.S86:0.2,self.S83:0.2,self.S62:0.2,self.S87:0.2},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S48:0.2,self.S88:0.2,self.S15:0.2,self.S86:0.2,self.S62:0.2},'2019-09-03':{self.S48:0.2,self.S88:0.2,self.S15:0.2,self.S86:0.2,self.S62:0.2},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S88:0.2,self.S48:0.2,self.S15:0.2,self.S86:0.2,self.S87:0.2},'2019-11-01':{self.S88:0.2,self.S48:0.2,self.S15:0.2,self.S86:0.2,self.S87:0.2},'2019-12-02':{self.S88:0.2,self.S89:0.2,self.S45:0.2,self.S26:0.2,self.S87:0.2},'2020-01-02':{self.S88:0.2,self.S89:0.2,self.S45:0.2,self.S26:0.2,self.S87:0.2},'2020-02-03':{self.S88:0.2,self.S45:0.2,self.S26:0.2,self.S87:0.2,self.S62:0.2},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S90:0.2,self.S91:0.2,self.S92:0.2,self.S93:0.2,self.S94:0.2},'2020-05-01':{self.S90:0.2,self.S91:0.2,self.S92:0.2,self.S93:0.2,self.S94:0.2},'2020-06-01':{self.S94:0.2,self.S95:0.2,self.S96:0.2,self.S57:0.2,self.S97:0.2},'2020-07-01':{self.S94:0.2,self.S95:0.2,self.S98:0.2,self.S96:0.2,self.S57:0.2},'2020-08-03':{self.S94:0.2,self.S98:0.2,self.S95:0.2,self.S96:0.2,self.S41:0.2},'2020-09-01':{self.S98:0.2,self.S99:0.2,self.S100:0.2,self.S19:0.2,self.S96:0.2},'2020-10-01':{self.S99:0.2,self.S100:0.2,self.S15:0.2,self.S101:0.2,self.S45:0.2},'2020-11-02':{self.S102:0.2,self.S99:0.2,self.S103:0.2,self.S104:0.2,self.S105:0.2},'2020-12-01':{self.S102:0.2,self.S97:0.2,self.S103:0.2,self.S91:0.2,self.S15: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)