Overall Statistics |
Total Trades 141 Average Win 24.87% Average Loss -2.37% Compounding Annual Return 25.428% Drawdown 29.800% Expectancy 2.606 Net Profit 2732.547% Sharpe Ratio 0.967 Probabilistic Sharpe Ratio 29.747% Loss Rate 69% Win Rate 31% Profit-Loss Ratio 10.47 Alpha 0 Beta 0 Annual Standard Deviation 0.199 Annual Variance 0.04 Information Ratio 0.967 Tracking Error 0.199 Treynor Ratio 0 Total Fees $25874.03 Estimated Strategy Capacity $150000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X |
from System.Drawing import Color class SMAStrategy(QCAlgorithm): def Initialize(self): self.SetStartDate(2007, 1, 1) self.SetEndDate(2021, 9, 30) self.SetCash(100000) self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage) self.stock = self.AddEquity("AAPL", Resolution.Daily).Symbol lenght = 100 self.sma = self.SMA(self.stock, lenght, Resolution.Daily) self.SetWarmUp(lenght, Resolution.Daily) self.Schedule.On(self.DateRules.EveryDay(self.stock), self.TimeRules.AfterMarketOpen(self.stock, 35), self.trade) stockPlot = Chart("Trade Plot") stockPlot.AddSeries(Series("Buy", SeriesType.Scatter, "$", Color.Green, ScatterMarkerSymbol.Triangle)) stockPlot.AddSeries(Series("Sell", SeriesType.Scatter, "$", Color.Red, ScatterMarkerSymbol.TriangleDown)) self.AddChart(stockPlot) def trade(self): if not self.sma.IsReady: return price = self.Securities[self.stock].Price tolerance = 0.0002 self.Plot("Trade Plot", "Price", price) self.Plot("Trade Plot", "SMA", self.sma.Current.Value) holdings = self.Portfolio[self.stock].Quantity if holdings <= 0: if self.sma.Current.Value <= price * (1 - tolerance): self.SetHoldings(self.stock,1) self.Plot("Trade Plot", "Buy", price) elif self.sma.Current.Value > price * (1 + tolerance): self.SetHoldings(self.stock, 0) self.Plot("Trade Plot", "Sell", price)