Overall Statistics
Total Trades
8
Average Win
0.58%
Average Loss
-0.60%
Compounding Annual Return
72.606%
Drawdown
0.600%
Expectancy
0.469
Net Profit
1.122%
Sharpe Ratio
5.62
Probabilistic Sharpe Ratio
83.200%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
0.96
Alpha
0.347
Beta
-0.019
Annual Standard Deviation
0.063
Annual Variance
0.004
Information Ratio
2.11
Tracking Error
0.317
Treynor Ratio
-18.131
Total Fees
$8.00
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.Hour)
        self.svxy.SetDataNormalizationMode(DataNormalizationMode.Raw) # Select Normalization Mode
        self.vxz = self.AddEquity("VXZ", Resolution.Hour)
        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
        
    def OnData(self, data):
        
        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 70, buy SVXY   
        if holdingsSVXY <= 0:
            if self.fast.Current.Value > 70: # when RSI2 above 70, 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 85, sell SVXY 
        if holdingsSVXY > 0:
            if self.fast.Current.Value < 85:
                self.Liquidate("SVXY")
                self.Debug(str(self.Portfolio["SVXY"].AveragePrice)) # Debug average price
                
        self.previous = self.Time
        
    def OnEndOfDay(self):
        self.Plot("Indicators","fastRSI", self.fast.Current.Value)