Overall Statistics
Total Trades
29
Average Win
0.23%
Average Loss
-0.05%
Compounding Annual Return
0.685%
Drawdown
0.900%
Expectancy
3.859
Net Profit
2.416%
Sharpe Ratio
0.593
Probabilistic Sharpe Ratio
17.834%
Loss Rate
15%
Win Rate
85%
Profit-Loss Ratio
4.74
Alpha
0.005
Beta
0.001
Annual Standard Deviation
0.01
Annual Variance
0
Information Ratio
-0.761
Tracking Error
0.197
Treynor Ratio
4.333
Total Fees
$46.03
Estimated Strategy Capacity
$65000000.00
Lowest Capacity Asset
AMD 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

        
#   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])

            # When slow sma > fast sma, sell the stock            
            if MA_Slow_Pre > MA_Fast_Pre:
                self.SetHoldings (stock, 0)
        

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