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
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.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from datetime import timedelta
from decimal import Decimal

import QuantConnect.Securities.Option
import QuantConnect.Securities.Equity


class OptionIssues(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2015, 12, 24)
        self.SetEndDate(2016, 1, 31)
        self.SetCash(10000)

        self.option = self.AddOption("GOOG")
        self.equity = self.AddEquity("GOOG", Resolution.Minute)
        
        # set our strike/expiry filter for this option chain
        self.min_days_to_expire = 7
        self.option.SetFilter(-10000000, +0, timedelta(self.min_days_to_expire), timedelta(40))

        # use the underlying equity as the benchmark
        self.SetBenchmark("GOOG")

        self.Schedule.On(
            self.DateRules.EveryDay(self.option.Symbol.Value),
            self.TimeRules.BeforeMarketClose(
                self.option.Symbol.Value,
                30),
            Action(self.action)
        )

    def action(self):
        contracts = list(filter(
            lambda x: isinstance(x, QuantConnect.Securities.Option.Option),
            self.Securities.Values)
        )
        puts = list(filter(
            lambda opt: opt.Right == OptionRight.Put,
            contracts
        ))

        expiry = sorted(
            puts,
            key=lambda opt: opt.Expiry,
        )
        
        self.Debug(
            'Current date: %s. First close contract: %s.' 
            'Days to expiry: %d. Min days constrain: %d' %
            (
                self.Time, 
                expiry[0].Expiry,
                (expiry[0].Expiry - self.Time).days,
                self.min_days_to_expire,
            )
        )
        return