Overall Statistics |
Total Trades 33 Average Win 9.39% Average Loss -3.77% Compounding Annual Return 9.534% Drawdown 21.400% Expectancy 0.964 Net Profit 72.725% Sharpe Ratio 0.814 Probabilistic Sharpe Ratio 29.164% Loss Rate 44% Win Rate 56% Profit-Loss Ratio 2.49 Alpha 0.007 Beta 0.511 Annual Standard Deviation 0.129 Annual Variance 0.017 Information Ratio -0.685 Tracking Error 0.126 Treynor Ratio 0.205 Total Fees $198.76 Estimated Strategy Capacity $160000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
# EMA Cross Algorithm # ------------------------------------------------------- STOCK = 'SPY'; MA_F = 15; MA_S = 30; TOLERANCE = 0.00015; # ------------------------------------------------------- class MovingAverageCrossAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2009, 1, 1) self.SetEndDate(2015, 1, 1) self.SetCash(100000) res = Resolution.Hour self.symbol = self.AddEquity(STOCK, res).Symbol self.SetWarmUp(5*MA_S, Resolution.Daily) self.ema_fast = self.EMA(self.symbol, MA_F, Resolution.Daily); self.ema_slow = self.EMA(self.symbol, MA_S, Resolution.Daily); self.Schedule.On(self.DateRules.WeekStart(self.symbol), self.TimeRules.AfterMarketOpen(self.symbol, 31), self.Rebalance) def Rebalance(self): if self.IsWarmingUp: return if not self.ema_fast.IsReady: return if not self.ema_slow: return self.Plot("EMAS", "ema_fast", self.ema_fast.Current.Value) self.Plot("EMAS", "ema_slow", self.ema_slow.Current.Value) if not self.Portfolio[self.symbol].IsLong: if self.ema_fast.Current.Value > self.ema_slow.Current.Value * (1 + TOLERANCE): # self.Log("BUY >> {0}".format(self.Securities[self.symbol].Price)) self.SetHoldings(self.symbol, 1.0) if self.Portfolio[self.symbol].IsLong: if self.ema_fast.Current.Value < self.ema_slow.Current.Value: # self.Log("SELL >> {0}".format(self.Securities[self.symbol].Price)) self.Liquidate(self.symbol)