Overall Statistics
Total Trades
5234
Average Win
0.15%
Average Loss
-0.11%
Compounding Annual Return
33.121%
Drawdown
25.800%
Expectancy
0.320
Net Profit
172.498%
Sharpe Ratio
1.498
Probabilistic Sharpe Ratio
74.038%
Loss Rate
44%
Win Rate
56%
Profit-Loss Ratio
1.34
Alpha
0.297
Beta
-0.052
Annual Standard Deviation
0.193
Annual Variance
0.037
Information Ratio
0.473
Tracking Error
0.283
Treynor Ratio
-5.53
Total Fees
$28992.95
Estimated Strategy Capacity
$1700000.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)
            # self.Debug(stocks)
            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.Debug (self.stocks_weight[stock])
                self.SetHoldings(stock, self.stocks_weight[stock]* 0.8)
                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 (stock, self.stocks_weight[stock] * 0.2)
                self.SetHoldings("GOLD", 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()