Overall Statistics |
Total Trades 44 Average Win 3.44% Average Loss -3.46% Compounding Annual Return -4.112% Drawdown 48.900% Expectancy 0.156 Net Profit -0.755% Sharpe Ratio 0.623 Probabilistic Sharpe Ratio 40.451% Loss Rate 42% Win Rate 58% Profit-Loss Ratio 1.00 Alpha 0.021 Beta 5.127 Annual Standard Deviation 1.02 Annual Variance 1.04 Information Ratio 0.588 Tracking Error 0.877 Treynor Ratio 0.124 Total Fees $81.40 |
class FuturesMovingAverageCrossOverExample2(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 1, 1) #Set Start Date self.SetEndDate(2018, 3,6) #Set End Date self.SetCash(100000) #Set Strategy Cash self.SetTimeZone('America/Los_Angeles') # Set timezone self.reset = True self.SymbolData = { } self.takeProfit = None self.stopLoss = None futureES = self.AddFuture(Futures.Indices.SP500EMini) futureES.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(360)) self.Schedule.On(self.DateRules.Every(DayOfWeek.Tuesday), self.TimeRules.At(9, 30), self.ScheduleDemo) def OnData(self, slice): # Reset any open positions based on a contract rollover. if self.reset: self.reset = False self.Log('RESET: closing all positions') self.Liquidate() def OnOrderEvent(self, orderEvent): if orderEvent.Status != OrderStatus.Filled: return id = orderEvent.OrderId if self.takeProfit is not None and id == self.takeProfit.OrderId: self.stopLoss.Cancel() if self.stopLoss is not None and id == self.stopLoss.OrderId: self.takeProfit.Cancel() def OnSecuritiesChanged(self, changes): for s in changes.AddedSecurities: if s.Symbol not in self.SymbolData: macd = self.MACD(s.Symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute) self.SymbolData[s.Symbol] = macd def ScheduleDemo(self): for symbol, assetData in self.SymbolData.items(): price = self.ActiveSecurities[symbol].Price if assetData: signalDeltaPercent = (assetData.Current.Value - assetData.Signal.Current.Value) currentPrice = price tolerance = 0.003 stopLossPrice = currentPrice - 100 profitTargetPrice = currentPrice + 50 holdings = self.Portfolio[symbol].Quantity if holdings <= 0 and signalDeltaPercent < 0 and signalDeltaPercent < -tolerance: # Go long self.MarketOrder(symbol, 1) self.takeProfit = self.LimitOrder(symbol, -1, profitTargetPrice) self.stopLoss = self.StopMarketOrder(symbol, 1, stopLossPrice) if holdings >= 0 and signalDeltaPercent > 0 and signalDeltaPercent > tolerance: #Go short self.MarketOrder(symbol, -1) self.takeProfit = self.LimitOrder(symbol, 1, profitTargetPrice) self.stopLoss = self.StopMarketOrder(symbol, -1, stopLossPrice)