Overall Statistics
Total Trades
3780
Average Win
0.26%
Average Loss
-0.27%
Compounding Annual Return
30.004%
Drawdown
23.700%
Expectancy
0.511
Net Profit
1489.861%
Sharpe Ratio
1.239
Probabilistic Sharpe Ratio
63.152%
Loss Rate
22%
Win Rate
78%
Profit-Loss Ratio
0.94
Alpha
0.187
Beta
0.636
Annual Standard Deviation
0.219
Annual Variance
0.048
Information Ratio
0.679
Tracking Error
0.204
Treynor Ratio
0.427
Total Fees
$12773.86
Estimated Strategy Capacity
$1100000.00
Lowest Capacity Asset
TMF UBTUG7D0B7TX
# Trading based on CBOE vix-vxv ratio

from QuantConnect.Data.Custom.CBOE import *

class VirtualRedDogfish(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2011, 1, 1)
        self.SetCash(100000) 
       
        self.AddEquity("QQQ", Resolution.Minute).Symbol
        self.AddEquity("TLT", Resolution.Minute).Symbol
        self.AddEquity("VXX", Resolution.Minute).Symbol
        self.AddEquity("SPY", Resolution.Minute).Symbol
        self.AddEquity("TQQQ", Resolution.Minute).Symbol
        self.AddEquity("TMF", Resolution.Minute).Symbol
        self.AddEquity("UVXY", Resolution.Minute).Symbol
        self.AddEquity("SVXY", Resolution.Minute).Symbol
        self.AddEquity("SSO", Resolution.Minute).Symbol
        self.AddEquity("QLD", Resolution.Minute).Symbol
        self.AddEquity("IEF", Resolution.Minute).Symbol
        self.AddEquity("UBT", Resolution.Minute).Symbol
        self.AddEquity("VTI", Resolution.Minute).Symbol

        self.vix = 'CBOE/VIX'
        self.vxv = 'CBOE/VXV'
       
        self.AddData(QuandlVix, self.vix, Resolution.Daily)
        self.AddData(Quandl, self.vxv, Resolution.Daily)
       
        self.SetWarmUp(100, Resolution.Daily)
       
        self.vix_sma = self.SMA(self.vix, 1, Resolution.Daily)
        self.vxv_sma = self.SMA(self.vxv, 1, Resolution.Daily)
        self.ratio = IndicatorExtensions.Over(self.vxv_sma, self.vix_sma)
       
        self.spySMA = self.SMA("SPY", 100, Resolution.Daily)
        self.spySMADaily = self.SMA("SPY",400, Resolution.Hour)
        
        self.Schedule.On(self.DateRules.WeekStart("QQQ"), self.TimeRules.AfterMarketOpen("QQQ", 10), self.WeekTrade)
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", 10), self.DayTrade)
       
       
    def WeekTrade(self):
        if not (self.vix_sma.IsReady or self.vxv_sma.IsReady or self.ratio.IsReady): 
            return
        if self.spySMA is None or not self.spySMA.IsReady: 
            return

        if self.Securities["SPY"].Price >= self.spySMA.Current.Value:
            # self.SetHoldings("SPY",0.25)
            # self.SetHoldings("IEF",0)
            
            if self.ratio.Current.Value < .923:
                
                self.SetHoldings("UVXY", 0.15)
                self.SetHoldings("TMF", 0.0)
                self.SetHoldings("TQQQ", 0.50)
                #self.SetHoldings("IEF", 0.0)
                
            else:
                self.SetHoldings("UVXY", 0.0)
                self.SetHoldings("TMF", 0.15)
                self.SetHoldings("TQQQ", 0.40)
                #self.SetHoldings("IEF", 0.0)
                self.SetHoldings
                if self.Securities["SPY"].Price >= 1.10*self.spySMA.Current.Value:
                    self.SetHoldings("UVXY", 0.07)
              
               
        else:
            # self.SetHoldings("SPY",0)
            # self.SetHoldings("IEF",0.25)
            
            if self.ratio.Current.Value <= .923:
                
                self.SetHoldings("UVXY", 0.15)
                self.SetHoldings("TMF", 0.10)
                self.SetHoldings("TQQQ", 0.06)
                #self.SetHoldings("IEF", 0.0)
                
            else:
                self.SetHoldings("UVXY", 0.0)
                self.SetHoldings("TMF", 0.18)
                self.SetHoldings("TQQQ", 0.15)
                #self.SetHoldings("IEF", 0.0)
                
                
               
                
    def DayTrade(self):
        if self.spySMADaily is None or not self.spySMADaily.IsReady: 
            return
        
        if self.Securities["SPY"].Price >= self.spySMADaily.Current.Value:
            self.SetHoldings("QLD", 0.30)
            self.SetHoldings("IEF", 0)
        else:
            self.SetHoldings("QLD", 0)
            self.SetHoldings("IEF", 0.60)
                
    
    
class QuandlVix(PythonQuandl):
   
    def __init__(self):
        self.ValueColumnName = "Close"