Overall Statistics |
Total Trades 714 Average Win 1.72% Average Loss -1.13% Compounding Annual Return 39.336% Drawdown 19.200% Expectancy 0.761 Net Profit 1871.950% Sharpe Ratio 1.854 Probabilistic Sharpe Ratio 95.538% Loss Rate 30% Win Rate 70% Profit-Loss Ratio 1.51 Alpha 0.381 Beta 0.209 Annual Standard Deviation 0.233 Annual Variance 0.054 Information Ratio 0.679 Tracking Error 0.275 Treynor Ratio 2.062 Total Fees $14065.69 |
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('MSB',res).Symbol self.S1=self.AddEquity('INCY',res).Symbol self.S2=self.AddEquity('STRA',res).Symbol self.S3=self.AddEquity('MD',res).Symbol self.S4=self.AddEquity('WHR',res).Symbol self.S5=self.AddEquity('WU',res).Symbol self.S6=self.AddEquity('FORM',res).Symbol self.S7=self.AddEquity('ARR',res).Symbol self.S8=self.AddEquity('VRSN',res).Symbol self.S9=self.AddEquity('GME',res).Symbol self.S10=self.AddEquity('NDAQ',res).Symbol self.S11=self.AddEquity('IMGN',res).Symbol self.S12=self.AddEquity('ITT',res).Symbol self.S13=self.AddEquity('INTU',res).Symbol self.S14=self.AddEquity('DPZ',res).Symbol self.S15=self.AddEquity('ACCO',res).Symbol self.S16=self.AddEquity('ABC',res).Symbol self.S17=self.AddEquity('PRDO',res).Symbol self.S18=self.AddEquity('CBOE',res).Symbol self.S19=self.AddEquity('LDOS',res).Symbol self.S20=self.AddEquity('RGR',res).Symbol self.S21=self.AddEquity('OMC',res).Symbol self.S22=self.AddEquity('CHH',res).Symbol self.S23=self.AddEquity('OVV',res).Symbol self.S24=self.AddEquity('AZPN',res).Symbol self.S25=self.AddEquity('GDOT',res).Symbol self.S26=self.AddEquity('NLOK',res).Symbol self.S27=self.AddEquity('VNDA',res).Symbol self.S28=self.AddEquity('IT',res).Symbol self.S29=self.AddEquity('XOMA',res).Symbol self.S30=self.AddEquity('ANSS',res).Symbol self.S31=self.AddEquity('FDS',res).Symbol self.S32=self.AddEquity('MA',res).Symbol self.S33=self.AddEquity('MSGN',res).Symbol self.S34=self.AddEquity('MOH',res).Symbol self.S35=self.AddEquity('PTCT',res).Symbol self.S36=self.AddEquity('EBAY',res).Symbol self.S37=self.AddEquity('WETF',res).Symbol self.S38=self.AddEquity('EIGI',res).Symbol self.S39=self.AddEquity('MANH',res).Symbol self.S40=self.AddEquity('UTHR',res).Symbol self.S41=self.AddEquity('HRB',res).Symbol self.S42=self.AddEquity('TMX',res).Symbol self.S43=self.AddEquity('SSYS',res).Symbol self.S44=self.AddEquity('CHRS',res).Symbol self.S45=self.AddEquity('MC',res).Symbol self.S46=self.AddEquity('SPGI',res).Symbol self.S47=self.AddEquity('ADP',res).Symbol self.S48=self.AddEquity('TDW',res).Symbol self.S49=self.AddEquity('ISEE',res).Symbol self.S50=self.AddEquity('TPL',res).Symbol self.S51=self.AddEquity('AGX',res).Symbol self.S52=self.AddEquity('PENN',res).Symbol self.S53=self.AddEquity('CLDX',res).Symbol self.S54=self.AddEquity('SPB',res).Symbol self.S55=self.AddEquity('FOSL',res).Symbol self.S56=self.AddEquity('BRO',res).Symbol self.S57=self.AddEquity('APAM',res).Symbol self.S58=self.AddEquity('QCOM',res).Symbol self.S59=self.AddEquity('MSCI',res).Symbol self.S60=self.AddEquity('RIOT',res).Symbol self.S61=self.AddEquity('VMW',res).Symbol self.S62=self.AddEquity('HEAR',res).Symbol self.S63=self.AddEquity('ARNA',res).Symbol self.S64=self.AddEquity('FPRX',res).Symbol self.S65=self.AddEquity('CTXS',res).Symbol self.S66=self.AddEquity('EQC',res).Symbol self.S67=self.AddEquity('LGND',res).Symbol self.S68=self.AddEquity('TGTX',res).Symbol self.S69=self.AddEquity('CTMX',res).Symbol self.S70=self.AddEquity('RETA',res).Symbol self.S71=self.AddEquity('ANAB',res).Symbol self.S72=self.AddEquity('DOMO',res).Symbol self.S73=self.AddEquity('DELL',res).Symbol self.S74=self.AddEquity('ARLO',res).Symbol self.S75=self.AddEquity('COOP',res).Symbol self.S76=self.AddEquity('UIS',res).Symbol self.S77=self.AddEquity('ESPR',res).Symbol self.S78=self.AddEquity('MRSN',res).Symbol self.S79=self.AddEquity('JEF',res).Symbol self.S80=self.AddEquity('INVA',res).Symbol self.S81=self.AddEquity('EIDX',res).Symbol self.S82=self.AddEquity('ENVA',res).Symbol self.S83=self.AddEquity('MTW',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.S0:0.2,self.S1:0.2,self.S2:0.2,self.S3:0.2,self.S4:0.2},'2012-03-01':{self.S0:0.2,self.S1:0.2,self.S2:0.2,self.S3:0.2,self.S5:0.2},'2012-04-02':{self.S0:0.2,self.S1:0.2,self.S2:0.2,self.S6:0.2,self.S7:0.2},'2012-05-01':{self.S0:0.2,self.S8:0.2,self.S1:0.2,self.S3:0.2,self.S7:0.2},'2012-06-01':{self.S0:0.2,self.S8:0.2,self.S1:0.2,self.S9:0.2,self.S5:0.2},'2012-07-02':{self.S0:0.2,self.S8:0.2,self.S1:0.2,self.S9:0.2,self.S5:0.2},'2012-08-01':{self.S0:0.2,self.S1:0.2,self.S9:0.2,self.S10:0.2,self.S5:0.2},'2012-09-04':{self.S11:0.2,self.S0:0.2,self.S1:0.2,self.S12:0.2,self.S10:0.2},'2012-10-01':{self.S11:0.2,self.S0:0.2,self.S1:0.2,self.S12:0.2,self.S10:0.2},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S0:0.2,self.S1:0.2,self.S5:0.2,self.S13:0.2,self.S9:0.2},'2012-12-03':{self.S0:0.2,self.S1:0.2,self.S5:0.2,self.S13:0.2,self.S3:0.2},'2013-01-02':{self.S1:0.2,self.S5:0.2,self.S13:0.2,self.S3:0.2,self.S14:0.2},'2013-02-01':{self.S1:0.2,self.S10:0.2,self.S5:0.2,self.S3:0.2,self.S13:0.2},'2013-03-01':{self.S10:0.2,self.S3:0.2,self.S15:0.2,self.S16:0.2,self.S5:0.2},'2013-04-01':{self.S17:0.2,self.S10:0.2,self.S15:0.2,self.S3:0.2,self.S16:0.2},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S17:0.2,self.S14:0.2,self.S18:0.2,self.S19:0.2,self.S20:0.2},'2013-06-03':{self.S17:0.2,self.S14:0.2,self.S18:0.2,self.S19:0.2,self.S20:0.2},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S14:0.2,self.S18:0.2,self.S20:0.2,self.S3:0.2,self.S21:0.2},'2013-08-01':{self.S17:0.2,self.S22:0.2,self.S21:0.2,self.S14:0.2,self.S18:0.2},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S17:0.2,self.S22:0.2,self.S21:0.2,self.S14:0.2,self.S3:0.2},'2013-09-03':{self.S17:0.2,self.S22:0.2,self.S21:0.2,self.S14:0.2,self.S3:0.2},'2013-10-01':{self.S17:0.2,self.S22:0.2,self.S21:0.2,self.S14:0.2,self.S3:0.2},'2013-11-01':{self.S11:0.2,self.S23:0.2,self.S21:0.2,self.S3:0.2,self.S14:0.2},'2013-12-02':{self.S11:0.2,self.S23:0.2,self.S21:0.2,self.S3:0.2,self.S14:0.2},'2014-01-02':{self.S11:0.2,self.S23:0.2,self.S21:0.2,self.S3:0.2,self.S14:0.2},'2014-02-03':{self.S23:0.2,self.S21:0.2,self.S3:0.2,self.S24:0.2,self.S14:0.2},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S11:0.2,self.S25:0.2,self.S21:0.2,self.S26:0.2,self.S24:0.2},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S11:0.2,self.S21:0.2,self.S25:0.2,self.S18:0.2,self.S24:0.2},'2014-07-01':{self.S11:0.2,self.S25:0.2,self.S21:0.2,self.S18:0.2,self.S24:0.2},'2014-08-01':{self.S11:0.2,self.S14:0.2,self.S21:0.2,self.S18:0.2,self.S3:0.2},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S27:0.2,self.S11:0.2,self.S24:0.2,self.S14:0.2,self.S21:0.2},'2014-09-02':{self.S27:0.2,self.S11:0.2,self.S24:0.2,self.S14:0.2,self.S21:0.2},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S11:0.2,self.S24:0.2,self.S21:0.2,self.S18:0.2,self.S28:0.2},'2015-03-02':{self.S11:0.2,self.S24:0.2,self.S21:0.2,self.S18:0.2,self.S28:0.2},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S11:0.2,self.S24:0.2,self.S29:0.2,self.S21:0.2,self.S18:0.2},'2015-05-01':{self.S24:0.2,self.S11:0.2,self.S29:0.2,self.S21:0.2,self.S18:0.2},'2015-06-01':{self.S24:0.2,self.S25:0.2,self.S11:0.2,self.S21:0.2,self.S18:0.2},'2015-07-01':{self.S24:0.2,self.S11:0.2,self.S21:0.2,self.S18:0.2,self.S30:0.2},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S24:0.2,self.S29:0.2,self.S21:0.2,self.S18:0.2,self.S14:0.2},'2015-10-01':{self.S24:0.2,self.S29:0.2,self.S21:0.2,self.S31:0.2,self.S14:0.2},'2015-11-02':{self.S29:0.2,self.S21:0.2,self.S31:0.2,self.S32:0.2,self.S14:0.2},'2015-12-01':{self.S33:0.2,self.S21:0.2,self.S34:0.2,self.S31:0.2,self.S32:0.2},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S24:0.2,self.S35:0.2,self.S33:0.2,self.S29:0.2,self.S36:0.2},'2016-04-01':{self.S35:0.2,self.S24:0.2,self.S33:0.2,self.S29:0.2,self.S36:0.2},'2016-05-02':{self.S33:0.2,self.S29:0.2,self.S37:0.2,self.S38:0.2,self.S39:0.2},'2016-06-01':{self.S33:0.2,self.S37:0.2,self.S34:0.2,self.S39:0.2,self.S40:0.2},'2016-07-01':{self.S33:0.2,self.S41:0.2,self.S37:0.2,self.S39:0.2,self.S40:0.2},'2016-08-01':{self.S33:0.2,self.S41:0.2,self.S37:0.2,self.S21:0.2,self.S39:0.2},'2016-09-01':{self.S33:0.2,self.S24:0.2,self.S37:0.2,self.S21:0.2,self.S39:0.2},'2016-10-03':{self.S33:0.2,self.S24:0.2,self.S37:0.2,self.S21:0.2,self.S39:0.2},'2016-11-01':{self.S11:0.2,self.S33:0.2,self.S24:0.2,self.S34:0.2,self.S37:0.2},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S42:0.2,self.S11:0.2,self.S24:0.2,self.S43:0.2,self.S33:0.2},'2017-02-01':{self.S42:0.2,self.S11:0.2,self.S24:0.2,self.S39:0.2,self.S43:0.2},'2017-03-01':{self.S42:0.2,self.S34:0.2,self.S24:0.2,self.S39:0.2,self.S43:0.2},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S44:0.2,self.S34:0.2,self.S24:0.2,self.S39:0.2,self.S45:0.2},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S11:0.2,self.S39:0.2,self.S34:0.2,self.S46:0.2,self.S47:0.2},'2017-07-03':{self.S11:0.2,self.S39:0.2,self.S34:0.2,self.S46:0.2,self.S47:0.2},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S11:0.2,self.S39:0.2,self.S34:0.2,self.S46:0.2,self.S47:0.2},'2017-08-01':{self.S11:0.2,self.S34:0.2,self.S39:0.2,self.S46:0.2,self.S47:0.2},'2017-09-01':{self.S42:0.2,self.S44:0.2,self.S48:0.2,self.S11:0.2,self.S39:0.2},'2017-10-02':{self.S42:0.2,self.S48:0.2,self.S44:0.2,self.S11:0.2,self.S39:0.2},'2017-11-01':{self.S48:0.2,self.S44:0.2,self.S11:0.2,self.S46:0.2,self.S21:0.2},'2017-12-01':{self.S48:0.2,self.S49:0.2,self.S46:0.2,self.S21:0.2,self.S39:0.2},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S48:0.2,self.S49:0.2,self.S46:0.2,self.S21:0.2,self.S39:0.2},'2018-01-02':{self.S48:0.2,self.S49:0.2,self.S46:0.2,self.S21:0.2,self.S39:0.2},'2018-02-01':{self.S24:0.2,self.S48:0.2,self.S49:0.2,self.S46:0.2,self.S50:0.2},'2018-03-01':{self.S24:0.2,self.S48:0.2,self.S49:0.2,self.S51:0.2,self.S52:0.2},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S24:0.2,self.S49:0.2,self.S53:0.2,self.S21:0.2,self.S39:0.2},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S24:0.2,self.S49:0.2,self.S21:0.2,self.S39:0.2,self.S54:0.2},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S55:0.2,self.S56:0.2,self.S57:0.2,self.S21:0.2,self.S39:0.2},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S55:0.2,self.S56:0.2,self.S57:0.2,self.S21:0.2,self.S39:0.2},'2019-02-01':{self.S58:0.2,self.S55:0.2,self.S57:0.2,self.S59:0.2,self.S21:0.2},'2019-03-01':{self.S58:0.2,self.S60:0.2,self.S8:0.2,self.S21:0.2,self.S46:0.2},'2019-04-01':{self.S58:0.2,self.S60:0.2,self.S8:0.2,self.S21:0.2,self.S46:0.2},'2019-05-01':{self.S8:0.2,self.S58:0.2,self.S60:0.2,self.S46:0.2,self.S59:0.2},'2019-06-03':{self.S8:0.2,self.S60:0.2,self.S61:0.2,self.S62:0.2,self.S63:0.2},'2019-06-26':{self.TLT:1.0},'2019-07-29':{self.S64:0.2,self.S61:0.2,self.S65:0.2,self.S8:0.2,self.S62:0.2},'2019-08-01':{self.S64:0.2,self.S61:0.2,self.S65:0.2,self.S66:0.2,self.S67:0.2},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S68:0.2,self.S64:0.2,self.S11:0.2,self.S65:0.2,self.S66:0.2},'2019-09-03':{self.S68:0.2,self.S64:0.2,self.S11:0.2,self.S65:0.2,self.S66:0.2},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S68:0.2,self.S69:0.2,self.S11:0.2,self.S64:0.2,self.S66:0.2},'2019-11-01':{self.S68:0.2,self.S69:0.2,self.S11:0.2,self.S64:0.2,self.S66:0.2},'2019-12-02':{self.S68:0.2,self.S11:0.2,self.S64:0.2,self.S70:0.2,self.S69:0.2},'2020-01-02':{self.S68:0.2,self.S71:0.2,self.S11:0.2,self.S70:0.2,self.S65:0.2},'2020-02-03':{self.S68:0.2,self.S69:0.2,self.S11:0.2,self.S70:0.2,self.S71:0.2},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S72:0.2,self.S73:0.2,self.S11:0.2,self.S74:0.2,self.S75:0.2},'2020-05-01':{self.S72:0.2,self.S73:0.2,self.S11:0.2,self.S76:0.2,self.S8:0.2},'2020-06-01':{self.S72:0.2,self.S77:0.2,self.S66:0.2,self.S76:0.2,self.S8:0.2},'2020-07-01':{self.S77:0.2,self.S78:0.2,self.S66:0.2,self.S76:0.2,self.S8:0.2},'2020-08-03':{self.S77:0.2,self.S78:0.2,self.S66:0.2,self.S76:0.2,self.S8:0.2},'2020-09-01':{self.S79:0.2,self.S66:0.2,self.S8:0.2,self.S33:0.2,self.S21:0.2},'2020-10-01':{self.S66:0.2,self.S8:0.2,self.S33:0.2,self.S21:0.2,self.S80:0.2},'2020-11-02':{self.S81:0.2,self.S66:0.2,self.S79:0.2,self.S33:0.2,self.S82:0.2},'2020-12-01':{self.S81:0.2,self.S66:0.2,self.S83:0.2,self.S79:0.2,self.S33: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)