Overall Statistics
Total Trades
12961
Average Win
0.14%
Average Loss
-0.12%
Compounding Annual Return
29.053%
Drawdown
26.800%
Expectancy
0.128
Net Profit
147.161%
Sharpe Ratio
1.282
Probabilistic Sharpe Ratio
61.393%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.22
Alpha
0.265
Beta
-0.038
Annual Standard Deviation
0.202
Annual Variance
0.041
Information Ratio
0.361
Tracking Error
0.286
Treynor Ratio
-6.895
Total Fees
$41676.59
Estimated Strategy Capacity
$96000000.00
Lowest Capacity Asset
ABX R735QTJ8XC9X
class MACrossover(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 1) # Set Start Date
    #    self.SetEndDate(2020, 1, 1) # Set End Date
        self.SetCash(100000) # Set Strategy Cash
        # self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        
        self.stop = False
        
        self.stocks = ["GOOG","TSLA", "JPM", "QCOM", "AMD", "FB","QQQ"]
        self.stocks_weight = {"GOOG":0.13, "TSLA":0.22, "JPM":0.08, "QCOM":0.13, "AMD":0.20, "FB":0.11, "QQQ":0.13 }
        self.AddEquity("GOOG", Resolution.Daily)    # Google
        self.AddEquity("TSLA", Resolution.Daily)    # Electric Cars, Solar & Clean Energy  
        self.AddEquity("JPM", Resolution.Daily)     # Banking / Finance
        self.AddEquity("QCOM", Resolution.Daily)    # Semiconductor stock
        self.AddEquity("AMD", Resolution.Daily)     # Semiconductor stock
        self.AddEquity("FB", Resolution.Daily)      # FaceBook
        self.AddEquity("QQQ", Resolution.Daily)     # QQQ is an etf that tracks Nasdaq index
        self.AddEquity("GOLD", Resolution.Daily)
        self.AddEquity("WMP", Resolution.Daily)
      
        
        self.SetWarmUp(50)

        
#   Part 2  Step 2: Calculate Moving Averages
    def OnData(self, data):
        
        if self.stop:
            return
        stocks = self.stocks
        
        for stock in stocks:
            # self.Debug(stock)
            stock_data = self.History ([stock], 30, Resolution.Daily)
            MA_Fast_Pre = stock_data.close[25:30].mean()
            MA_Slow_Pre = stock_data.close [9:30].mean()
#
#   Part 3 Strategy: Make Crossover rule
#    
            # When slow sma < fast sma, buy the stock
            if MA_Slow_Pre < MA_Fast_Pre:
                # self.Debug (self.stocks_weight[stock])
                    # self.SetHoldings(stock, self.stocks_weight[stock]* 0.8)
                self.SetHoldings([PortfolioTarget("GOOG", 0.13*0.8), PortfolioTarget("TSLA", 0.22*0.8), PortfolioTarget("JPM", 0.08*0.8),PortfolioTarget("QCOM", 0.13*0.8), PortfolioTarget("AMD",0.2*0.8), PortfolioTarget("FB", 0.11*0.8), PortfolioTarget("QQQ", 0.13*0.8), PortfolioTarget("GOLD", 0.05), PortfolioTarget("WMP", 0.05)])
                # self.SetHoldings("GOLD", 0.1)
                # self.SetHoldings("WMP", 0.1)

            # When slow sma > fast sma, sell the stock            
            if MA_Slow_Pre > MA_Fast_Pre:
                self.SetHoldings([PortfolioTarget("GOOG", 0.13*0.2), PortfolioTarget("TSLA", 0.22*0.2), PortfolioTarget("JPM", 0.08*0.2),PortfolioTarget("QCOM", 0.13*0.2), PortfolioTarget("AMD",0.2*0.2), PortfolioTarget("FB", 0.11*0.2), PortfolioTarget("QQQ", 0.13*0.2), PortfolioTarget("GOLD", 0.4), PortfolioTarget("WMP", 0.4)])
            
                # self.SetHoldings("WMP", 0.4)
        

#   Part 4  Step 4: Make Drawdown stop
            
        # if self.Portfolio.Cash < 0.85*1000:
        #     self.stop = True
        #     self.Liquidate()