Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Data import *
from QuantConnect.Algorithm import *
from QuantConnect.Securities import *
from QuantConnect.Indicators import *

from datetime import timedelta
from enum import Enum

import numpy as np


'''
Issues with VIX options
'''


class OptionsPerformanceIssueAlgo(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2018, 1, 2)
        self.SetEndDate(2018, 1, 2)

        self.SetCash(15000)

        # self.option = self.AddOption('SPY', Resolution.Minute)
        self.option = self.AddOption('VIX', Resolution.Minute)
        self.option.SetFilter(-100, 100, timedelta(7), timedelta(360))

        # self.asset_underlying = self.AddEquity(self.option.Symbol.Underlying, Resolution.Minute)
        self.asset_underlying = self.AddEquity('SPY', Resolution.Minute)
        
        self.slice = None
        
        self.trade_hours = [180]
        for minutes in self.trade_hours:
            self.Schedule.On(
                self.DateRules.EveryDay(self.asset_underlying.Symbol),
                self.TimeRules.AfterMarketOpen(self.asset_underlying.Symbol, minutes),
                Action(self._trade_test)
            )


    def OnData(self, slice):
        self.slice = slice


    def _trade_test(self):
        if self.slice is None:
            return []
            
        underlying_chains = [chain for chain in self.slice.OptionChains]

        if len(underlying_chains) == 0:
            self.Log('No option contract')
            
            return
        
        underlying_chain = underlying_chains[0].Value
        
        calls = list(filter(
            lambda opt: opt.Right == OptionRight.Call,
            underlying_chain,
        ))
        
        puts = list(filter(
            lambda opt: opt.Right == OptionRight.Put,
            underlying_chain,
        ))

        self.Log('There are %d calls and %d puts' % (len(calls), len(puts)))
        return