Overall Statistics |
Total Trades 15 Average Win 0.85% Average Loss -0.81% Compounding Annual Return 56.451% Drawdown 4.900% Expectancy 0.174 Net Profit 1.539% Sharpe Ratio 2.803 Probabilistic Sharpe Ratio 64.544% Loss Rate 43% Win Rate 57% Profit-Loss Ratio 1.05 Alpha 0.276 Beta -0.094 Annual Standard Deviation 0.117 Annual Variance 0.014 Information Ratio 2.699 Tracking Error 0.322 Treynor Ratio -3.475 Total Fees $28.38 |
import numpy as np ### <summary> ### Basic template algorithm simply initializes the date range and cash. This is a skeleton ### framework you can use for designing an algorithm. ### </summary> class BasicTemplateAlgorithm(QCAlgorithm): '''Basic template algorithm simply initializes the date range and cash''' def Initialize(self): self.SetStartDate(2019, 12, 1) #Set Start Date self.SetEndDate(datetime.now().date() - timedelta(1)) # Set End Date self.SetCash(10000) #Set Strategy Cash self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage) # Set Brokerage Model self.SetTimeZone("America/New_York") # Set Time Zone # Find more symbols here: http://quantconnect.com/data self.svxy = self.AddEquity("SVXY", Resolution.Minute) self.svxy.SetDataNormalizationMode(DataNormalizationMode.Raw) # Select Normalization Mode self.vxz = self.AddEquity("VXZ", Resolution.Minute) self.vxz.SetDataNormalizationMode(DataNormalizationMode.Raw) # Select Normalization Mode self.fast = self.RSI("SVXY", 6, MovingAverageType.Simple, Resolution.Hour) # define a period RSI indicator #self.slow = self.RSI("SVXY", 15, MovingAverageType.Simple, Resolution.Hour) # define a period RSI indicator self.previous = None self.SetBenchmark("SVXY") # Set Benchmark self.SetWarmUp(20, Resolution.Hour) # Set Warm Up #for m in range (29,330,60): # 9:59 AM - 2:59 PM #self.Schedule.On(self.DateRules.EveryDay("SVXY"), self.TimeRules.AfterMarketOpen("SVXY", minutes=m), Action(self.OnDataCopy)) self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SVXY", 29), Action(self.OnDataCopy)) #9:59 AM self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SVXY", 89), Action(self.OnDataCopy)) #10:59 AM self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SVXY", 149), Action(self.OnDataCopy)) #11:59 AM self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SVXY", 209), Action(self.OnDataCopy)) #12:59 PM self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SVXY", 269), Action(self.OnDataCopy)) #1:59 PM self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SVXY", 329), Action(self.OnDataCopy)) #2:59 PM self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("SVXY", 1), Action(self.OnDataCopy)) #3:59 PM def OnData(self, data): pass def OnDataCopy(self): if self.IsWarmingUp: # Don't place trades until our indicators are warmed up return holdingsSVXY = self.Portfolio["SVXY"].Quantity holdingsVXZ = self.Portfolio["VXZ"].Quantity # when fastRSI above 50, buy SVXY & sell VXZ #if holdingsSVXY <= 0: if self.fast.Current.Value > 50: # when RSIfast above 50, sell VXZ & buy SVXY self.Liquidate("VXZ") self.Debug(str(self.Portfolio["VXZ"].AveragePrice)) # Debug average price self.SetHoldings("SVXY", 1.0, True) self.Debug(str(self.Portfolio["SVXY"].AveragePrice)) # Debug average price #closeSVXY = self.Portfolio["SVXY"].AveragePrice #stopMarketTicketSVXY = self.StopMarketOrder("SVXY",-self.Portfolio['SVXY'].Quantity, closeSVXY * 0.90) # when fastRSI below 50, sell SVXY & buy VXZ #if holdingsSVXY <= 0: if self.fast.Current.Value < 50: # when RSIfast below 50, sell SVXY & buy VXZ self.Liquidate("SVXY") self.Debug(str(self.Portfolio["SVXY"].AveragePrice)) # Debug average price self.SetHoldings("VXZ", 1.0, True) self.Debug(str(self.Portfolio["VXZ"].AveragePrice)) # Debug average price #closeVXZ = self.Portfolio["VXZ"].AveragePrice #stopMarketTicketVXZ = self.StopMarketOrder("VXZ",-self.Portfolio['VXZ'].Quantity, closeVXZ * 0.90) self.previous = self.Time def OnEndOfDay(self): self.Plot("Indicators","fastRSI", self.fast.Current.Value)