Overall Statistics |
Total Trades 11 Average Win 0% Average Loss -9.35% Compounding Annual Return -86.504% Drawdown 71.800% Expectancy -1 Net Profit -30.335% Sharpe Ratio -0.172 Probabilistic Sharpe Ratio 28.323% Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -1.186 Beta 7.783 Annual Standard Deviation 1.469 Annual Variance 2.157 Information Ratio -0.284 Tracking Error 1.315 Treynor Ratio -0.033 Total Fees $19.50 |
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.takeProfitL = None self.stopLossL = None self.takeProfitS = None self.stopLossS = None self.AddEquity("SPY", Resolution.Minute) futureES = self.AddFuture(Futures.Indices.SP500EMini) futureES.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(360)) self.Schedule.On(self.DateRules.Every(DayOfWeek.Tuesday), self.TimeRules.AfterMarketOpen("SPY", 10), 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.takeProfitL is not None and id == self.takeProfitL.OrderId: self.stopLossL.Cancel() self.Debug("0") if self.takeProfitS is not None and id == self.takeProfitS.OrderId: self.stopLossS.Cancel() self.Debug("0") if self.stopLossL is not None and id == self.stopLossL.OrderId: self.takeProfitL.Cancel() self.Debug("1") if self.stopLossS is not None and id == self.stopLossS.OrderId: self.takeProfitS.Cancel() self.Debug("1") 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): tolerance = 0.003 for symbol, assetData in self.SymbolData.items(): if self.Portfolio[symbol].Invested: continue price = self.ActiveSecurities[symbol].Price if assetData: signalDeltaPercent = (assetData.Current.Value - assetData.Signal.Current.Value) if signalDeltaPercent < 0 and signalDeltaPercent < -tolerance: # Go long stopLossPrice = price*0.8 profitTargetPrice = price*1.2 self.MarketOrder(symbol, 1) self.takeProfitL = self.LimitOrder(symbol, -1, profitTargetPrice) self.stopLossL = self.StopMarketOrder(symbol, -1, stopLossPrice) if signalDeltaPercent > 0 and signalDeltaPercent > tolerance: #Go short stopLossPrice = price*0.8 profitTargetPrice = price*1.2 self.MarketOrder(symbol, -1) self.takeProfitS = self.LimitOrder(symbol, 1, profitTargetPrice) self.stopLossS = self.StopMarketOrder(symbol, 1, stopLossPrice)