Overall Statistics |
Total Trades 712 Average Win 1.67% Average Loss -1.46% Compounding Annual Return 26.287% Drawdown 26.300% Expectancy 0.441 Net Profit 714.385% Sharpe Ratio 1.224 Probabilistic Sharpe Ratio 58.491% Loss Rate 33% Win Rate 67% Profit-Loss Ratio 1.14 Alpha 0.247 Beta 0.226 Annual Standard Deviation 0.247 Annual Variance 0.061 Information Ratio 0.198 Tracking Error 0.285 Treynor Ratio 1.339 Total Fees $10524.99 |
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('VECO',res).Symbol self.S1=self.AddEquity('FORM',res).Symbol self.S2=self.AddEquity('XPER',res).Symbol self.S3=self.AddEquity('CVI',res).Symbol self.S4=self.AddEquity('VSH',res).Symbol self.S5=self.AddEquity('UIS',res).Symbol self.S6=self.AddEquity('GME',res).Symbol self.S7=self.AddEquity('SNX',res).Symbol self.S8=self.AddEquity('KRO',res).Symbol self.S9=self.AddEquity('GDOT',res).Symbol self.S10=self.AddEquity('TKR',res).Symbol self.S11=self.AddEquity('APO',res).Symbol self.S12=self.AddEquity('CEQP',res).Symbol self.S13=self.AddEquity('TROX',res).Symbol self.S14=self.AddEquity('PRDO',res).Symbol self.S15=self.AddEquity('LDOS',res).Symbol self.S16=self.AddEquity('HFC',res).Symbol self.S17=self.AddEquity('DK',res).Symbol self.S18=self.AddEquity('CF',res).Symbol self.S19=self.AddEquity('KDP',res).Symbol self.S20=self.AddEquity('NTGR',res).Symbol self.S21=self.AddEquity('IEP',res).Symbol self.S22=self.AddEquity('OVV',res).Symbol self.S23=self.AddEquity('NLOK',res).Symbol self.S24=self.AddEquity('VC',res).Symbol self.S25=self.AddEquity('REGI',res).Symbol self.S26=self.AddEquity('DXC',res).Symbol self.S27=self.AddEquity('JOE',res).Symbol self.S28=self.AddEquity('GHC',res).Symbol self.S29=self.AddEquity('REX',res).Symbol self.S30=self.AddEquity('SAFM',res).Symbol self.S31=self.AddEquity('ARLP',res).Symbol self.S32=self.AddEquity('CENX',res).Symbol self.S33=self.AddEquity('MSGN',res).Symbol self.S34=self.AddEquity('GBX',res).Symbol self.S35=self.AddEquity('MOH',res).Symbol self.S36=self.AddEquity('BKE',res).Symbol self.S37=self.AddEquity('PTCT',res).Symbol self.S38=self.AddEquity('ADVM',res).Symbol self.S39=self.AddEquity('WDR',res).Symbol self.S40=self.AddEquity('FPRX',res).Symbol self.S41=self.AddEquity('HPQ',res).Symbol self.S42=self.AddEquity('FSLR',res).Symbol self.S43=self.AddEquity('ISEE',res).Symbol self.S44=self.AddEquity('SSYS',res).Symbol self.S45=self.AddEquity('PINC',res).Symbol self.S46=self.AddEquity('MC',res).Symbol self.S47=self.AddEquity('GLIBA',res).Symbol self.S48=self.AddEquity('AGX',res).Symbol self.S49=self.AddEquity('TDW',res).Symbol self.S50=self.AddEquity('FL',res).Symbol self.S51=self.AddEquity('MGNI',res).Symbol self.S52=self.AddEquity('NPO',res).Symbol self.S53=self.AddEquity('APAM',res).Symbol self.S54=self.AddEquity('CLDX',res).Symbol self.S55=self.AddEquity('EQC',res).Symbol self.S56=self.AddEquity('BEN',res).Symbol self.S57=self.AddEquity('MU',res).Symbol self.S58=self.AddEquity('RYAM',res).Symbol self.S59=self.AddEquity('BCEI',res).Symbol self.S60=self.AddEquity('LGND',res).Symbol self.S61=self.AddEquity('VRS',res).Symbol self.S62=self.AddEquity('HEAR',res).Symbol self.S63=self.AddEquity('ARNA',res).Symbol self.S64=self.AddEquity('HCC',res).Symbol self.S65=self.AddEquity('CTMX',res).Symbol self.S66=self.AddEquity('ANAB',res).Symbol self.S67=self.AddEquity('ARLO',res).Symbol self.S68=self.AddEquity('PUMP',res).Symbol self.S69=self.AddEquity('CNNE',res).Symbol self.S70=self.AddEquity('NOG',res).Symbol self.S71=self.AddEquity('JEF',res).Symbol self.S72=self.AddEquity('WOR',res).Symbol self.S73=self.AddEquity('INVA',res).Symbol self.S74=self.AddEquity('VYGR',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.S0:0.2,self.S3:0.2,self.S5:0.2,self.S4:0.2},'2012-03-01':{self.S1:0.2,self.S5:0.2,self.S3:0.2,self.S2:0.2,self.S6:0.2},'2012-04-02':{self.S1:0.2,self.S6:0.2,self.S5:0.2,self.S3:0.2,self.S7:0.2},'2012-05-01':{self.S5:0.2,self.S6:0.2,self.S4:0.2,self.S3:0.2,self.S7:0.2},'2012-06-01':{self.S2:0.2,self.S5:0.2,self.S6:0.2,self.S8:0.2,self.S7:0.2},'2012-07-02':{self.S6:0.2,self.S8:0.2,self.S5:0.2,self.S7:0.2,self.S4:0.2},'2012-08-01':{self.S6:0.2,self.S9:0.2,self.S5:0.2,self.S10:0.2,self.S8:0.2},'2012-09-04':{self.S9:0.2,self.S3:0.2,self.S5:0.2,self.S7:0.2,self.S10:0.2},'2012-10-01':{self.S10:0.2,self.S5:0.2,self.S7:0.2,self.S8:0.2,self.S9:0.2},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S11:0.2,self.S3:0.2,self.S9:0.2,self.S5:0.2,self.S7:0.2},'2012-12-03':{self.S11:0.2,self.S5:0.2,self.S12:0.2,self.S3:0.2,self.S7:0.2},'2013-01-02':{self.S11:0.2,self.S5:0.2,self.S12:0.2,self.S9:0.2,self.S7:0.2},'2013-02-01':{self.S11:0.2,self.S12:0.2,self.S7:0.2,self.S9:0.2,self.S5:0.2},'2013-03-01':{self.S11:0.2,self.S7:0.2,self.S5:0.2,self.S13:0.2,self.S9:0.2},'2013-04-01':{self.S14:0.2,self.S11:0.2,self.S7:0.2,self.S15:0.2,self.S5:0.2},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S14:0.2,self.S7:0.2,self.S15:0.2,self.S16:0.2,self.S5:0.2},'2013-06-03':{self.S14:0.2,self.S7:0.2,self.S15:0.2,self.S16:0.2,self.S3:0.2},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S16:0.2,self.S3:0.2,self.S17:0.2,self.S18:0.2,self.S15:0.2},'2013-08-01':{self.S14:0.2,self.S3:0.2,self.S16:0.2,self.S17:0.2,self.S19:0.2},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S14:0.2,self.S3:0.2,self.S17:0.2,self.S16:0.2,self.S19:0.2},'2013-09-03':{self.S14:0.2,self.S3:0.2,self.S17:0.2,self.S16:0.2,self.S19:0.2},'2013-10-01':{self.S14:0.2,self.S3:0.2,self.S17:0.2,self.S16:0.2,self.S19:0.2},'2013-11-01':{self.S3:0.2,self.S17:0.2,self.S16:0.2,self.S20:0.2,self.S7:0.2},'2013-12-02':{self.S3:0.2,self.S21:0.2,self.S22:0.2,self.S7:0.2,self.S20:0.2},'2014-01-02':{self.S3:0.2,self.S21:0.2,self.S22:0.2,self.S7:0.2,self.S11:0.2},'2014-02-03':{self.S3:0.2,self.S21:0.2,self.S23:0.2,self.S22:0.2,self.S7:0.2},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S9:0.2,self.S23:0.2,self.S24:0.2,self.S21:0.2,self.S20:0.2},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S9:0.2,self.S25:0.2,self.S24:0.2,self.S26:0.2,self.S3:0.2},'2014-07-01':{self.S9:0.2,self.S25:0.2,self.S24:0.2,self.S26:0.2,self.S3:0.2},'2014-08-01':{self.S9:0.2,self.S25:0.2,self.S24:0.2,self.S26:0.2,self.S27:0.2},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S9:0.2,self.S28:0.2,self.S21:0.2,self.S26:0.2,self.S23:0.2},'2014-09-02':{self.S9:0.2,self.S28:0.2,self.S21:0.2,self.S26:0.2,self.S23:0.2},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S29:0.2,self.S27:0.2,self.S19:0.2,self.S23:0.2,self.S20:0.2},'2015-03-02':{self.S29:0.2,self.S27:0.2,self.S19:0.2,self.S30:0.2,self.S9:0.2},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S30:0.2,self.S27:0.2,self.S19:0.2,self.S23:0.2,self.S31:0.2},'2015-05-01':{self.S30:0.2,self.S27:0.2,self.S19:0.2,self.S23:0.2,self.S20:0.2},'2015-06-01':{self.S9:0.2,self.S28:0.2,self.S30:0.2,self.S29:0.2,self.S19:0.2},'2015-07-01':{self.S9:0.2,self.S28:0.2,self.S30:0.2,self.S29:0.2,self.S31:0.2},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S9:0.2,self.S29:0.2,self.S30:0.2,self.S32:0.2,self.S33:0.2},'2015-10-01':{self.S9:0.2,self.S29:0.2,self.S32:0.2,self.S30:0.2,self.S4:0.2},'2015-11-02':{self.S30:0.2,self.S9:0.2,self.S29:0.2,self.S33:0.2,self.S34:0.2},'2015-12-01':{self.S34:0.2,self.S35:0.2,self.S30:0.2,self.S36:0.2,self.S29:0.2},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S37:0.2,self.S38:0.2,self.S39:0.2,self.S34:0.2,self.S40:0.2},'2016-04-01':{self.S37:0.2,self.S38:0.2,self.S39:0.2,self.S34:0.2,self.S40:0.2},'2016-05-02':{self.S38:0.2,self.S39:0.2,self.S34:0.2,self.S35:0.2,self.S41:0.2},'2016-06-01':{self.S35:0.2,self.S34:0.2,self.S39:0.2,self.S36:0.2,self.S38:0.2},'2016-07-01':{self.S39:0.2,self.S35:0.2,self.S34:0.2,self.S40:0.2,self.S36:0.2},'2016-08-01':{self.S39:0.2,self.S34:0.2,self.S35:0.2,self.S36:0.2,self.S38:0.2},'2016-09-01':{self.S38:0.2,self.S35:0.2,self.S39:0.2,self.S34:0.2,self.S42:0.2},'2016-10-03':{self.S38:0.2,self.S39:0.2,self.S34:0.2,self.S35:0.2,self.S36:0.2},'2016-11-01':{self.S35:0.2,self.S39:0.2,self.S34:0.2,self.S38:0.2,self.S36:0.2},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S43:0.2,self.S44:0.2,self.S35:0.2,self.S38:0.2,self.S39:0.2},'2017-02-01':{self.S43:0.2,self.S44:0.2,self.S35:0.2,self.S38:0.2,self.S39:0.2},'2017-03-01':{self.S35:0.2,self.S43:0.2,self.S44:0.2,self.S36:0.2,self.S45:0.2},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S35:0.2,self.S43:0.2,self.S46:0.2,self.S39:0.2,self.S36:0.2},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S43:0.2,self.S35:0.2,self.S47:0.2,self.S36:0.2,self.S39:0.2},'2017-07-03':{self.S43:0.2,self.S35:0.2,self.S47:0.2,self.S36:0.2,self.S48:0.2},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S43:0.2,self.S35:0.2,self.S36:0.2,self.S47:0.2,self.S48:0.2},'2017-08-01':{self.S43:0.2,self.S35:0.2,self.S36:0.2,self.S47:0.2,self.S48:0.2},'2017-09-01':{self.S49:0.2,self.S43:0.2,self.S36:0.2,self.S45:0.2,self.S39:0.2},'2017-10-02':{self.S49:0.2,self.S43:0.2,self.S36:0.2,self.S45:0.2,self.S48:0.2},'2017-11-01':{self.S49:0.2,self.S43:0.2,self.S36:0.2,self.S45:0.2,self.S50:0.2},'2017-12-01':{self.S49:0.2,self.S51:0.2,self.S48:0.2,self.S45:0.2,self.S52:0.2},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S49:0.2,self.S48:0.2,self.S51:0.2,self.S45:0.2,self.S52:0.2},'2018-01-02':{self.S49:0.2,self.S48:0.2,self.S51:0.2,self.S45:0.2,self.S52:0.2},'2018-02-01':{self.S49:0.2,self.S48:0.2,self.S51:0.2,self.S45:0.2,self.S52:0.2},'2018-03-01':{self.S49:0.2,self.S48:0.2,self.S51:0.2,self.S52:0.2,self.S53:0.2},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S54:0.2,self.S48:0.2,self.S52:0.2,self.S53:0.2,self.S55:0.2},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S48:0.2,self.S52:0.2,self.S53:0.2,self.S56:0.2,self.S55:0.2},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S53:0.2,self.S48:0.2,self.S57:0.2,self.S58:0.2,self.S39:0.2},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S53:0.2,self.S57:0.2,self.S39:0.2,self.S58:0.2,self.S48:0.2},'2019-02-01':{self.S53:0.2,self.S39:0.2,self.S57:0.2,self.S58:0.2,self.S56:0.2},'2019-03-01':{self.S59:0.2,self.S57:0.2,self.S39:0.2,self.S5:0.2,self.S55:0.2},'2019-04-01':{self.S59:0.2,self.S39:0.2,self.S5:0.2,self.S25:0.2,self.S57:0.2},'2019-05-01':{self.S55:0.2,self.S5:0.2,self.S59:0.2,self.S35:0.2,self.S25:0.2},'2019-06-03':{self.S60:0.2,self.S55: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.S40:0.2,self.S60:0.2,self.S61:0.2,self.S55:0.2,self.S64:0.2},'2019-08-01':{self.S40:0.2,self.S55:0.2,self.S60:0.2,self.S61:0.2,self.S64:0.2},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S40:0.2,self.S55:0.2,self.S60:0.2,self.S64:0.2,self.S61:0.2},'2019-09-03':{self.S40:0.2,self.S55:0.2,self.S60:0.2,self.S64:0.2,self.S61:0.2},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S65:0.2,self.S40:0.2,self.S55:0.2,self.S60:0.2,self.S59:0.2},'2019-11-01':{self.S65:0.2,self.S40:0.2,self.S55:0.2,self.S60:0.2,self.S64:0.2},'2019-12-02':{self.S40:0.2,self.S65:0.2,self.S66:0.2,self.S55:0.2,self.S60:0.2},'2020-01-02':{self.S66:0.2,self.S55:0.2,self.S60:0.2,self.S9:0.2,self.S64:0.2},'2020-02-03':{self.S65:0.2,self.S66:0.2,self.S60:0.2,self.S55:0.2,self.S64:0.2},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S67:0.2,self.S60:0.2,self.S68:0.2,self.S56:0.2,self.S64:0.2},'2020-05-01':{self.S60:0.2,self.S68:0.2,self.S55:0.2,self.S25:0.2,self.S31:0.2},'2020-06-01':{self.S55:0.2,self.S68:0.2,self.S69:0.2,self.S59:0.2,self.S70:0.2},'2020-07-01':{self.S55:0.2,self.S59:0.2,self.S25:0.2,self.S69:0.2,self.S70:0.2},'2020-08-03':{self.S55:0.2,self.S69:0.2,self.S25:0.2,self.S70:0.2,self.S59:0.2},'2020-09-01':{self.S55:0.2,self.S71:0.2,self.S69:0.2,self.S25:0.2,self.S61:0.2},'2020-10-01':{self.S55:0.2,self.S61:0.2,self.S69:0.2,self.S72:0.2,self.S73:0.2},'2020-11-02':{self.S55:0.2,self.S71:0.2,self.S61:0.2,self.S69:0.2,self.S73:0.2},'2020-12-01':{self.S55:0.2,self.S71:0.2,self.S69:0.2,self.S74:0.2,self.S73: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)