Overall Statistics |
Total Trades 2264 Average Win 2.57% Average Loss -1.22% Compounding Annual Return 63.761% Drawdown 25.700% Expectancy 0.269 Net Profit 2590.077% Sharpe Ratio 1.463 Loss Rate 59% Win Rate 41% Profit-Loss Ratio 2.11 Alpha 0.337 Beta 0.309 Annual Standard Deviation 0.311 Annual Variance 0.097 Information Ratio 0.148 Tracking Error 0.498 Treynor Ratio 1.47 Total Fees $88672.64 |
import numpy as np from clr import AddReference AddReference("System") AddReference("NodaTime") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Indicators") AddReference("QuantConnect.Common") from System import * from NodaTime import DateTimeZone from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Brokerages import * from QuantConnect.Data.Market import * class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): # Set the cash we'd like to use for our backtest # This is ignored in live trading self.SetCash(37000) # Start and end dates for the backtest. # These are ignored in live trading. self.SetStartDate(2011,06,8) self.SetEndDate(2018,2,6) #Assets predetermined #self.uvxy = self.AddEquity("UVXY", Resolution.Hour).Symbol self.svxy = self.AddEquity("SVXY", Resolution.Hour, None, True, 1, True).Symbol self.spy = self.AddEquity("SPY", Resolution.Hour, None, True, 1, True).Symbol # Indicators self.emaBig = self.EMA("SVXY", 5, Resolution.Hour) self.emaSmall = self.EMA("SVXY", 2, Resolution.Hour) # Schedules self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(16, 1), Action(self.EveryDayBeforeMarketClose)) self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(9, 59), Action(self.EveryDayAfterMarketOpen)) self.Schedule.On(self.DateRules.On(2018, 1, 22), self.TimeRules.At(13, 0), Action(self.SpecificTime)) # Timers self.w = 1 # Set benchmark self.SetBenchmark("SVXY") # Get warmup data so that the Algorithm can start trading self.SetWarmUp(5) # Counters self.case1 = 0 self.case2 = 0 def OnData(self, data): if self.w == 0: if not self.Portfolio.Invested: if self.emaBig < self.emaSmall: self.case1 += 1 self.SetHoldings(self.svxy, 0.85) else: if self.emaBig > self.emaSmall: self.case2 += 1 self.SetHoldings(self.svxy, 0) def EveryDayBeforeMarketClose(self): if self.w == 0: self.w = 1 #self.Log('Market Close') def EveryDayAfterMarketOpen(self): self.w = 0 #self.Log('Market Open') def SpecificTime(self): self.Log('Case 1: {}'.format(self.case1)) self.Log('Case 2: {}'.format(self.case2))