Overall Statistics
Total Trades
15
Average Win
2.46%
Average Loss
-0.65%
Compounding Annual Return
279.570%
Drawdown
4.100%
Expectancy
1.052
Net Profit
4.658%
Sharpe Ratio
4.114
Probabilistic Sharpe Ratio
73.171%
Loss Rate
57%
Win Rate
43%
Profit-Loss Ratio
3.79
Alpha
0.851
Beta
-0.247
Annual Standard Deviation
0.239
Annual Variance
0.057
Information Ratio
3.697
Tracking Error
0.412
Treynor Ratio
-3.992
Total Fees
$29.31
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.Open)) #9:59 AM
        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)