Overall Statistics
Total Trades
385
Average Win
1.22%
Average Loss
-1.54%
Compounding Annual Return
3.490%
Drawdown
21.600%
Expectancy
0.203
Net Profit
77.888%
Sharpe Ratio
0.551
Probabilistic Sharpe Ratio
3.274%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.79
Alpha
0.006
Beta
0.281
Annual Standard Deviation
0.066
Annual Variance
0.004
Information Ratio
-0.528
Tracking Error
0.135
Treynor Ratio
0.13
Total Fees
$986.42
from QuantConnect.Data.Custom.CBOE import CBOE

class VerticalTransdimensionalAutosequencers(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2003, 1, 1)
        self.SetEndDate(2019, 10, 11)
        self.SetCash(100000)
        
        self.previous = 0.0
        self.lastTrade = datetime(1, 1, 1)
        
        self.cboeVix = self.AddData(CBOE, "VIX").Symbol
        self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol

    def OnData(self, data):
        # Only trade after 10 days have passed since we last traded
        if (self.Time - self.lastTrade) < timedelta(days=10):
            return
        
        # Liquidate our holdings after 10 days
        if self.Portfolio.Invested:
            self.Liquidate(self.spy)
        
        # Trading on the reversion to the mean by using 
        # VIX as a proxy for the mean
        if not data.ContainsKey(self.cboeVix):
            return
        
        vix = data.Get(CBOE, self.cboeVix)
        current = vix.Close
        
        if self.previous != 0:
            # Calculate the percentage, and if it is greater than 10%
            # we long SPY for 10 days
            percentageChange = (current - self.previous) / self.previous
            
            if percentageChange > 0.10:
                self.SetHoldings(self.spy, 0.5)
                self.lastTrade = self.Time
            
        # Store the previous value for percentage calculation
        self.previous = vix.Close