Overall Statistics |
Total Trades 7199 Average Win 0.15% Average Loss -0.11% Compounding Annual Return 41.337% Drawdown 47.000% Expectancy 0.327 Net Profit 235.168% Sharpe Ratio 1.129 Probabilistic Sharpe Ratio 45.146% Loss Rate 44% Win Rate 56% Profit-Loss Ratio 1.38 Alpha 0.478 Beta -0.308 Annual Standard Deviation 0.381 Annual Variance 0.145 Information Ratio 0.602 Tracking Error 0.456 Treynor Ratio -1.397 Total Fees $27293.96 Estimated Strategy Capacity $2300000.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 = ["CSCO","TSLA", "JPM", "QCOM", "AMD", "TLT","QQQ"] self.stocks_weight = {"CSCO":0.1, "TSLA":0.1, "JPM":0.1, "QCOM":0.1, "AMD":0.1, "TLT":0.1, "QQQ":0.1 } 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 self.AddEquity("GOLD", Resolution.Daily) self.AddEquity("WMP", Resolution.Daily) # 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]) self.SetHoldings("GOLD", 0.15) self.SetHoldings("WMP", 0.15) # When slow sma > fast sma, sell the stock if MA_Slow_Pre > MA_Fast_Pre: self.SetHoldings(stock, 0.3) self.SetHoldings("GOLD", 0.35) self.SetHoldings("WMP", 0.35) # Part 4 Step 4: Make Drawdown stop # if self.Portfolio.Cash < 0.85*1000: # self.stop = True # self.Liquidate()