Overall Statistics
from System import * # CLR namespaces to be treatedas Python packages
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Python import PythonQuandl
from datetime import datetime, timedelta
from decimal import Decimal
import numpy as np

class VolPySplit(QCAlgorithm):

    def Initialize(context):

        context.SetStartDate(2018, 6, 7)
        context.SetEndDate(2018, 6, 12)
        context.SetCash(100000)

        context.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)

        # add the #2 ETFs (short and long VIX futures)
        context.L1 = context.AddEquity("TVIX", Resolution.Minute).Symbol


        context.Schedule.On(context.DateRules.On(2018, 6, 7),
                context.TimeRules.At(10,00),
                Action(context.buy_stock))

        context.Schedule.On(context.DateRules.On(2018, 6, 12),
                context.TimeRules.At(10,00),
                Action(context.log_data))

    def buy_stock(context):
        context.SetHoldings(context.L1, 100)
        context.Log("{0} bought {1} at ${2}".format(context.L1, context.Portfolio[context.L1].Quantity, context.Portfolio[context.L1].AveragePrice))


    def log_data(context):
        context.Log("{0} currently holds {1} at ${2}".format(context.L1, context.Portfolio[context.L1].Quantity, context.Securities['TVIX'].Price))