Overall Statistics
from datetime import timedelta

class BasicTemplateOptionsAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 2, 1)
        self.SetEndDate(2017, 3, 1)
        self.SetCash(100000)

        option = self.AddOption("IBM")
        self.option_symbol = option.Symbol
        option.SetFilter(-10, +10, timedelta(0), timedelta(30))


    def OnData(self,slice):
        if self.Portfolio.Invested: return

        chain = slice.OptionChains.GetValue(self.option_symbol)
        if chain is None:
            return
        contracts = sorted(chain, key = lambda x: x.Strike)
        if len(contracts) == 0: return
        symbol = contracts[-1].Symbol
        if not self.Portfolio.Invested:
            self.MarketOrder(symbol, 1)
 

    def OnOrderEvent(self, orderEvent):
        self.Debug("IBM Price "+str(self.Securities["IBM"].Price))
        self.Log(str(orderEvent))