Overall Statistics
Total Trades
617
Average Win
4.66%
Average Loss
-0.22%
Compounding Annual Return
-1.998%
Drawdown
54.800%
Expectancy
-0.245
Net Profit
-22.436%
Sharpe Ratio
-0.023
Loss Rate
97%
Win Rate
3%
Profit-Loss Ratio
20.89
Alpha
0.151
Beta
-7.756
Annual Standard Deviation
0.179
Annual Variance
0.032
Information Ratio
-0.135
Tracking Error
0.179
Treynor Ratio
0.001
Total Fees
$815.16
import numpy as np
from QuantConnect.Python import PythonQuandl

class VIXPredictsStockIndexReturns(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2006, 1, 1)  
        self.SetEndDate(2018, 8, 1)    
        self.SetCash(100000)          
        self.AddEquity("OEF", Resolution.Daily)
        self.vix = 'CBOE/VIX'
        self.AddData(QuandlVix, self.vix, Resolution.Daily)
        self.window = RollingWindow[float](252*2)
        hist = self.History([self.vix], 1000, Resolution.Daily)
        for close in hist.loc[self.vix]['vix close']:
            self.window.Add(close)


    def OnData(self, data):
        if not data.ContainsKey(self.vix): return
        self.window.Add(self.Securities[self.vix].Price)
        if not self.window.IsReady: return 
        history_close = [i for i in self.window]

        if self.Securities[self.vix].Price > np.percentile(history_close, 90):
            self.SetHoldings("OEF", 1)
        elif self.Securities[self.vix].Price < np.percentile(history_close, 10):
            self.SetHoldings("OEF", -1)
        
    
class QuandlVix(PythonQuandl):
    
    def __init__(self):
        self.ValueColumnName = "VIX Close"