Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
7.133%
Drawdown
11.600%
Expectancy
0
Net Profit
14.775%
Sharpe Ratio
0.554
Probabilistic Sharpe Ratio
23.624%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.065
Beta
0.011
Annual Standard Deviation
0.119
Annual Variance
0.014
Information Ratio
-0.006
Tracking Error
0.17
Treynor Ratio
6.142
Total Fees
$1.00
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Python import PythonQuandl
from datetime import datetime, timedelta

class ParticleResistanceComputer(QCAlgorithm):


    def Initialize(self):
        ''' Initialize the data and resolution you require for your strategy '''
        self.quandl_first = "CHRIS/CBOE_VX1"
        self.quandl_next = "CHRIS/CBOE_VX2"
        self.SetStartDate(2014, 1, 1)
        self.SetEndDate(2015, 12, 31)
        #self.SetEndDate(datetime.now().date() - timedelta(1))
        self.SetCash(1000)
        self.AddEquity("SPY", Resolution.Daily)

        # Symbol corresponding to the quandl code
        self.vx1 = self.AddData(QuandlVix, self.quandl_first, Resolution.Daily)
        self.vx3 = self.AddData(QuandlVix, self.quandl_next, Resolution.Daily)


    def OnData(self, data):
        '''Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.'''
        if data.ContainsKey("CHRIS/CBOE_VX1") and data.ContainsKey("CHRIS/CBOE_VX2"): 
            if self.Securities['CHRIS/CBOE_VX1'].Price <  self.Securities['CHRIS/CBOE_VX2'].Price:
                self.SetHoldings('SPY', 1)
        else:
            if not data.ContainsKey("CHRIS/CBOE_VX1"):
                self.Log('vx1 not found')
            if not data.ContainsKey("CHRIS/CBOE_VX2"):
                self.Log('vx2 not found')


        
class QuandlVix(PythonQuandl):
    
    def __init__(self):
        self.ValueColumnName = "Open"