Overall Statistics Total Trades15Average Win0.85%Average Loss-0.81%Compounding Annual Return56.451%Drawdown4.900%Expectancy0.174Net Profit1.539%Sharpe Ratio2.803Probabilistic Sharpe Ratio64.544%Loss Rate43%Win Rate57%Profit-Loss Ratio1.05Alpha0.276Beta-0.094Annual Standard Deviation0.117Annual Variance0.014Information Ratio2.699Tracking Error0.322Treynor Ratio-3.475Total 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.SetDataNormalizationMode(DataNormalizationMode.Raw) # Select Normalization Mode
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)