Overall Statistics
Total Trades
679
Average Win
1.49%
Average Loss
-1.15%
Compounding Annual Return
29.740%
Drawdown
19.600%
Expectancy
0.544
Net Profit
944.467%
Sharpe Ratio
1.609
Probabilistic Sharpe Ratio
87.953%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
1.29
Alpha
0.245
Beta
0.324
Annual Standard Deviation
0.202
Annual Variance
0.041
Information Ratio
0.337
Tracking Error
0.232
Treynor Ratio
1.003
Total Fees
$6929.76
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('AAPL',res).Symbol
        self.S1=self.AddEquity('FORM',res).Symbol
        self.S2=self.AddEquity('MSFT',res).Symbol
        self.S3=self.AddEquity('GOOGL',res).Symbol
        self.S4=self.AddEquity('XOM',res).Symbol
        self.S5=self.AddEquity('NVR',res).Symbol
        self.S6=self.AddEquity('BKNG',res).Symbol
        self.S7=self.AddEquity('CMG',res).Symbol
        self.S8=self.AddEquity('MSB',res).Symbol
        self.S9=self.AddEquity('UIS',res).Symbol
        self.S10=self.AddEquity('AMZN',res).Symbol
        self.S11=self.AddEquity('IMGN',res).Symbol
        self.S12=self.AddEquity('ARNA',res).Symbol
        self.S13=self.AddEquity('SNX',res).Symbol
        self.S14=self.AddEquity('WDC',res).Symbol
        self.S15=self.AddEquity('REGN',res).Symbol
        self.S16=self.AddEquity('AZO',res).Symbol
        self.S17=self.AddEquity('BCEI',res).Symbol
        self.S18=self.AddEquity('HPQ',res).Symbol
        self.S19=self.AddEquity('DK',res).Symbol
        self.S20=self.AddEquity('NTGR',res).Symbol
        self.S21=self.AddEquity('CRUS',res).Symbol
        self.S22=self.AddEquity('STRA',res).Symbol
        self.S23=self.AddEquity('TTWO',res).Symbol
        self.S24=self.AddEquity('REGI',res).Symbol
        self.S25=self.AddEquity('MOH',res).Symbol
        self.S26=self.AddEquity('FB',res).Symbol
        self.S27=self.AddEquity('REX',res).Symbol
        self.S28=self.AddEquity('PEIX',res).Symbol
        self.S29=self.AddEquity('AZPN',res).Symbol
        self.S30=self.AddEquity('CENX',res).Symbol
        self.S31=self.AddEquity('PINC',res).Symbol
        self.S32=self.AddEquity('MSGN',res).Symbol
        self.S33=self.AddEquity('GILD',res).Symbol
        self.S34=self.AddEquity('PTCT',res).Symbol
        self.S35=self.AddEquity('SPB',res).Symbol
        self.S36=self.AddEquity('TMX',res).Symbol
        self.S37=self.AddEquity('ISEE',res).Symbol
        self.S38=self.AddEquity('TDW',res).Symbol
        self.S39=self.AddEquity('CLDX',res).Symbol
        self.S40=self.AddEquity('BPT',res).Symbol
        self.S41=self.AddEquity('NVDA',res).Symbol
        self.S42=self.AddEquity('AKBA',res).Symbol
        self.S43=self.AddEquity('TSLA',res).Symbol
        self.S44=self.AddEquity('LJPC',res).Symbol
        self.S45=self.AddEquity('NFLX',res).Symbol
        self.S46=self.AddEquity('VRSN',res).Symbol
        self.S47=self.AddEquity('FPRX',res).Symbol
        self.S48=self.AddEquity('CTMX',res).Symbol
        self.S49=self.AddEquity('TGTX',res).Symbol
        self.S50=self.AddEquity('ANAB',res).Symbol
        self.S51=self.AddEquity('CABO',res).Symbol
        self.S52=self.AddEquity('VIVE',res).Symbol
        self.S53=self.AddEquity('DOMO',res).Symbol
        self.S54=self.AddEquity('RMED',res).Symbol
        self.S55=self.AddEquity('EIDX',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.S3:0.2,self.S2:0.2,self.S4:0.2},'2012-03-01':{self.S0:0.2,self.S3:0.2,self.S5:0.2,self.S1:0.2,self.S4:0.2},'2012-04-02':{self.S0:0.2,self.S5:0.2,self.S6:0.2,self.S7:0.2,self.S3:0.2},'2012-05-01':{self.S0:0.2,self.S8:0.2,self.S6:0.2,self.S7:0.2,self.S5:0.2},'2012-06-01':{self.S0:0.2,self.S6:0.2,self.S8:0.2,self.S7:0.2,self.S2:0.2},'2012-07-02':{self.S0:0.2,self.S8:0.2,self.S6:0.2,self.S2:0.2,self.S9:0.2},'2012-08-01':{self.S0:0.2,self.S8:0.2,self.S5:0.2,self.S6:0.2,self.S10:0.2},'2012-09-04':{self.S0:0.2,self.S11:0.2,self.S5:0.2,self.S8:0.2,self.S12:0.2},'2012-10-01':{self.S0:0.2,self.S11:0.2,self.S13:0.2,self.S9:0.2,self.S8:0.2},'2012-10-09':{self.TLT:1.0},'2012-11-12':{self.S0:0.2,self.S8:0.2,self.S3:0.2,self.S13:0.2,self.S14:0.2},'2012-12-03':{self.S0:0.2,self.S8:0.2,self.S3:0.2,self.S13:0.2,self.S14:0.2},'2013-01-02':{self.S0:0.2,self.S13:0.2,self.S3:0.2,self.S5:0.2,self.S9:0.2},'2013-02-01':{self.S0:0.2,self.S5:0.2,self.S13:0.2,self.S9:0.2,self.S14:0.2},'2013-03-01':{self.S0:0.2,self.S5:0.2,self.S13:0.2,self.S14:0.2,self.S6:0.2},'2013-04-01':{self.S0:0.2,self.S5:0.2,self.S13:0.2,self.S6:0.2,self.S14:0.2},'2013-04-22':{self.TLT:1.0},'2013-05-24':{self.S0:0.2,self.S5:0.2,self.S13:0.2,self.S3:0.2,self.S6:0.2},'2013-06-03':{self.S0:0.2,self.S5:0.2,self.S13:0.2,self.S3:0.2,self.S6:0.2},'2013-06-07':{self.TLT:1.0},'2013-07-15':{self.S0:0.2,self.S6:0.2,self.S3:0.2,self.S15:0.2,self.S16:0.2},'2013-08-01':{self.S0:0.2,self.S17:0.2,self.S6:0.2,self.S18:0.2,self.S19:0.2},'2013-08-02':{self.TLT:1.0},'2013-08-22':{self.S0:0.2,self.S6:0.2,self.S20:0.2,self.S18:0.2,self.S13:0.2},'2013-09-03':{self.S0:0.2,self.S6:0.2,self.S18:0.2,self.S20:0.2,self.S13:0.2},'2013-10-01':{self.S0:0.2,self.S17:0.2,self.S18:0.2,self.S19:0.2,self.S6:0.2},'2013-11-01':{self.S0:0.2,self.S17:0.2,self.S18:0.2,self.S20:0.2,self.S21:0.2},'2013-12-02':{self.S0:0.2,self.S17:0.2,self.S11:0.2,self.S21:0.2,self.S18:0.2},'2014-01-02':{self.S0:0.2,self.S17:0.2,self.S11:0.2,self.S21:0.2,self.S22:0.2},'2014-02-03':{self.S0:0.2,self.S17:0.2,self.S6:0.2,self.S21:0.2,self.S22:0.2},'2014-02-05':{self.TLT:1.0},'2014-05-06':{self.S0:0.2,self.S5:0.2,self.S23:0.2,self.S11:0.2,self.S6:0.2},'2014-05-21':{self.TLT:1.0},'2014-06-12':{self.S0:0.2,self.S24:0.2,self.S17:0.2,self.S11:0.2,self.S23:0.2},'2014-07-01':{self.S0:0.2,self.S24:0.2,self.S17:0.2,self.S11:0.2,self.S23:0.2},'2014-08-01':{self.S0:0.2,self.S17:0.2,self.S24:0.2,self.S11:0.2,self.S23:0.2},'2014-08-04':{self.TLT:1.0},'2014-08-29':{self.S0:0.2,self.S17:0.2,self.S23:0.2,self.S25:0.2,self.S18:0.2},'2014-09-02':{self.S0:0.2,self.S17:0.2,self.S23:0.2,self.S25:0.2,self.S18:0.2},'2014-09-04':{self.TLT:1.0},'2015-02-23':{self.S0:0.2,self.S25:0.2,self.S26:0.2,self.S27:0.2,self.S2:0.2},'2015-03-02':{self.S0:0.2,self.S25:0.2,self.S26:0.2,self.S27:0.2,self.S28:0.2},'2015-03-12':{self.TLT:1.0},'2015-04-07':{self.S0:0.2,self.S25:0.2,self.S26:0.2,self.S2:0.2,self.S28:0.2},'2015-05-01':{self.S0:0.2,self.S25:0.2,self.S26:0.2,self.S2:0.2,self.S3:0.2},'2015-06-01':{self.S0:0.2,self.S25:0.2,self.S17:0.2,self.S26:0.2,self.S29:0.2},'2015-07-01':{self.S0:0.2,self.S6:0.2,self.S25:0.2,self.S10:0.2,self.S26:0.2},'2015-07-27':{self.TLT:1.0},'2015-09-17':{self.S0:0.2,self.S29:0.2,self.S26:0.2,self.S30:0.2,self.S27:0.2},'2015-10-01':{self.S0:0.2,self.S29:0.2,self.S26:0.2,self.S25:0.2,self.S27:0.2},'2015-11-02':{self.S0:0.2,self.S25:0.2,self.S31:0.2,self.S26:0.2,self.S27:0.2},'2015-12-01':{self.S0:0.2,self.S25:0.2,self.S26:0.2,self.S32:0.2,self.S33:0.2},'2015-12-30':{self.TLT:1.0},'2016-03-22':{self.S34:0.2,self.S0:0.2,self.S29:0.2,self.S26:0.2,self.S3:0.2},'2016-04-01':{self.S34:0.2,self.S0:0.2,self.S29:0.2,self.S26:0.2,self.S32:0.2},'2016-05-02':{self.S0:0.2,self.S26:0.2,self.S32:0.2,self.S2:0.2,self.S33:0.2},'2016-06-01':{self.S0:0.2,self.S32:0.2,self.S26:0.2,self.S25:0.2,self.S6:0.2},'2016-07-01':{self.S0:0.2,self.S6:0.2,self.S10:0.2,self.S26:0.2,self.S32:0.2},'2016-08-01':{self.S10:0.2,self.S0:0.2,self.S6:0.2,self.S26:0.2,self.S32:0.2},'2016-09-01':{self.S35:0.2,self.S0:0.2,self.S10:0.2,self.S26:0.2,self.S2:0.2},'2016-10-03':{self.S35:0.2,self.S0:0.2,self.S10:0.2,self.S26:0.2,self.S6:0.2},'2016-11-01':{self.S35:0.2,self.S0:0.2,self.S10:0.2,self.S6:0.2,self.S26:0.2},'2016-11-11':{self.TLT:1.0},'2017-01-11':{self.S36:0.2,self.S0:0.2,self.S37:0.2,self.S26:0.2,self.S10:0.2},'2017-02-01':{self.S36:0.2,self.S35:0.2,self.S0:0.2,self.S26:0.2,self.S10:0.2},'2017-03-01':{self.S36:0.2,self.S25:0.2,self.S0:0.2,self.S26:0.2,self.S10:0.2},'2017-03-06':{self.TLT:1.0},'2017-04-18':{self.S25:0.2,self.S0:0.2,self.S5:0.2,self.S10:0.2,self.S6:0.2},'2017-04-20':{self.TLT:1.0},'2017-06-12':{self.S0:0.2,self.S10:0.2,self.S5:0.2,self.S6:0.2,self.S26:0.2},'2017-07-03':{self.S0:0.2,self.S10:0.2,self.S5:0.2,self.S26:0.2,self.S11:0.2},'2017-07-07':{self.TLT:1.0},'2017-07-31':{self.S0:0.2,self.S10:0.2,self.S5:0.2,self.S26:0.2,self.S3:0.2},'2017-08-01':{self.S0:0.2,self.S10:0.2,self.S5:0.2,self.S26:0.2,self.S25:0.2},'2017-09-01':{self.S0:0.2,self.S10:0.2,self.S26:0.2,self.S38:0.2,self.S25:0.2},'2017-10-02':{self.S38:0.2,self.S0:0.2,self.S10:0.2,self.S26:0.2,self.S25:0.2},'2017-11-01':{self.S0:0.2,self.S38:0.2,self.S10:0.2,self.S26:0.2,self.S25:0.2},'2017-12-01':{self.S38:0.2,self.S0:0.2,self.S10:0.2,self.S26:0.2,self.S25:0.2},'2017-12-04':{self.TLT:1.0},'2017-12-27':{self.S0:0.2,self.S38:0.2,self.S10:0.2,self.S26:0.2,self.S25:0.2},'2018-01-02':{self.S0:0.2,self.S38:0.2,self.S10:0.2,self.S26:0.2,self.S25:0.2},'2018-02-01':{self.S38:0.2,self.S0:0.2,self.S10:0.2,self.S5:0.2,self.S26:0.2},'2018-03-01':{self.S10:0.2,self.S0:0.2,self.S38:0.2,self.S5:0.2,self.S26:0.2},'2018-03-26':{self.TLT:1.0},'2018-08-10':{self.S10:0.2,self.S39:0.2,self.S0:0.2,self.S40:0.2,self.S26:0.2},'2018-08-17':{self.TLT:1.0},'2018-10-01':{self.S10:0.2,self.S40:0.2,self.S0:0.2,self.S26:0.2,self.S3:0.2},'2018-10-25':{self.TLT:1.0},'2018-11-20':{self.S10:0.2,self.S40:0.2,self.S0:0.2,self.S26:0.2,self.S41:0.2},'2018-11-23':{self.TLT:1.0},'2019-01-17':{self.S40:0.2,self.S42:0.2,self.S0:0.2,self.S10:0.2,self.S26:0.2},'2019-02-01':{self.S40:0.2,self.S0:0.2,self.S26:0.2,self.S43:0.2,self.S2:0.2},'2019-03-01':{self.S44:0.2,self.S0:0.2,self.S40:0.2,self.S26:0.2,self.S43:0.2},'2019-04-01':{self.S10:0.2,self.S0:0.2,self.S26:0.2,self.S41:0.2,self.S2:0.2},'2019-05-01':{self.S10:0.2,self.S0:0.2,self.S26:0.2,self.S41:0.2,self.S45:0.2},'2019-06-03':{self.S10:0.2,self.S46:0.2,self.S40:0.2,self.S0:0.2,self.S26:0.2},'2019-06-26':{self.TLT:1.0},'2019-07-29':{self.S10:0.2,self.S40:0.2,self.S0:0.2,self.S47:0.2,self.S5:0.2},'2019-08-01':{self.S10:0.2,self.S40:0.2,self.S0:0.2,self.S47:0.2,self.S5:0.2},'2019-08-05':{self.TLT:1.0},'2019-08-27':{self.S47:0.2,self.S10:0.2,self.S0:0.2,self.S5:0.2,self.S26:0.2},'2019-09-03':{self.S47:0.2,self.S10:0.2,self.S0:0.2,self.S5:0.2,self.S26:0.2},'2019-09-17':{self.TLT:1.0},'2019-10-31':{self.S48:0.2,self.S10:0.2,self.S0:0.2,self.S26:0.2,self.S5:0.2},'2019-11-01':{self.S48:0.2,self.S10:0.2,self.S0:0.2,self.S26:0.2,self.S5:0.2},'2019-12-02':{self.S40:0.2,self.S10:0.2,self.S0:0.2,self.S48:0.2,self.S26:0.2},'2020-01-02':{self.S40:0.2,self.S49:0.2,self.S0:0.2,self.S10:0.2,self.S50:0.2},'2020-02-03':{self.S48:0.2,self.S10:0.2,self.S0:0.2,self.S40:0.2,self.S51:0.2},'2020-02-20':{self.TLT:1.0},'2020-04-24':{self.S10:0.2,self.S52:0.2,self.S0:0.2,self.S53:0.2,self.S43:0.2},'2020-05-01':{self.S52:0.2,self.S10:0.2,self.S0:0.2,self.S53:0.2,self.S43:0.2},'2020-06-01':{self.S52:0.2,self.S10:0.2,self.S0:0.2,self.S53:0.2,self.S43:0.2},'2020-07-01':{self.S10:0.2,self.S52:0.2,self.S0:0.2,self.S54:0.2,self.S2:0.2},'2020-08-03':{self.S10:0.2,self.S52:0.2,self.S0:0.2,self.S54:0.2,self.S43:0.2},'2020-09-01':{self.S10:0.2,self.S0:0.2,self.S43:0.2,self.S5:0.2,self.S2:0.2},'2020-10-01':{self.S10:0.2,self.S5:0.2,self.S0:0.2,self.S43:0.2,self.S2:0.2},'2020-11-02':{self.S10:0.2,self.S43:0.2,self.S0:0.2,self.S5:0.2,self.S55:0.2},'2020-12-01':{self.S10:0.2,self.S43:0.2,self.S0:0.2,self.S55:0.2,self.S5: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)