Overall Statistics |
Total Trades 39 Average Win 10.27% Average Loss -13.21% Compounding Annual Return -99.992% Drawdown 95.900% Expectancy -0.667 Net Profit -86.310% Sharpe Ratio -0.308 Probabilistic Sharpe Ratio 19.570% Loss Rate 81% Win Rate 19% Profit-Loss Ratio 0.78 Alpha -2.706 Beta 13.399 Annual Standard Deviation 2.648 Annual Variance 7.01 Information Ratio -0.381 Tracking Error 2.514 Treynor Ratio -0.061 Total Fees $81.40 |
import clr import decimal as d import pandas as pd class FuturesMovingAverageCrossOverExample2(QCAlgorithm): def Initialize(self): self.contract = None self.SetStartDate(2018, 1, 1) #Set Start Date self.SetEndDate(2018, 6,6) #Set End Date self.SetCash(100000) #Set Strategy Cash self.SetWarmUp(TimeSpan.FromDays(5)) # Set warm up self.SetTimeZone('America/Los_Angeles') # Set timezone self.new_day = True self.reset = True self.limitOrderTicket = None self.profitTargetOrderTicket = None self.stopLossOrderTicket = None # Risk management # Subscribe and set our expiry filter for the futures chain self.SymbolData = { } futureES = self.AddFuture(Futures.Indices.SP500EMini) futureES.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(360)) self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday), self.TimeRules.At(9, 30), self.ScheduleDemo) # Indicators 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 OnSecuritiesChanged(self, changes): for s in changes.AddedSecurities: if s.Symbol not in self.SymbolData: history = self.History(s.Symbol, 30, Resolution.Hour) self.__macd = self.MACD(s.Symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute) self.SymbolData[s.Symbol] = self.__macd def ScheduleDemo(self): for symbol, assetData in self.SymbolData.items(): price = self.ActiveSecurities[symbol].Price if assetData: self.Log("2") 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.Buy(symbol, 1) self.LimitOrder(symbol, -1, profitTargetPrice) self.StopMarketOrder(symbol, -1, stopLossPrice) self.Log("0") if holdings >= 0 and signalDeltaPercent > 0 and signalDeltaPercent > tolerance : #Go short self.Buy(symbol, -1) self.LimitOrder(symbol, 1, profitTargetPrice) self.StopMarketOrder(symbol, 1, stopLossPrice) self.Log("1")