Overall Statistics
Total Trades
125
Average Win
0.04%
Average Loss
-0.16%
Compounding Annual Return
-0.536%
Drawdown
10.200%
Expectancy
-0.182
Net Profit
-1.861%
Sharpe Ratio
-0.094
Probabilistic Sharpe Ratio
1.095%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.23
Alpha
-0.003
Beta
-0.004
Annual Standard Deviation
0.039
Annual Variance
0.002
Information Ratio
-0.788
Tracking Error
0.202
Treynor Ratio
1
Total Fees
$172.46
Estimated Strategy Capacity
$350000000.00
Lowest Capacity Asset
CSCO 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 = ["CSCO","TSLA", "JPM", "QCOM", "AMD", "TLT","QQQ"]
        self.stocks_weight = {"CSCO":0.05, "TSLA":0.1, "JPM":0.1, "QCOM":0.05, "AMD":0.3, "TLT":0.1, "QQQ":0.3 }
        self.AddEquity("CSCO", Resolution.Daily)    # Networking hardware, software, telecommunications equipment
        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("TLT", Resolution.Daily)     # TLT is an etf of US Treasury bond
        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()