Overall Statistics
Total Trades
8
Average Win
1.69%
Average Loss
-3.27%
Compounding Annual Return
0.354%
Drawdown
0.200%
Expectancy
0.011
Net Profit
0.058%
Sharpe Ratio
0.602
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.52
Alpha
0.001
Beta
0.007
Annual Standard Deviation
0.005
Annual Variance
0
Information Ratio
-2.89
Tracking Error
0.107
Treynor Ratio
0.446
Total Fees
$3.00
from datetime import timedelta
from math import floor,ceil

class BasicTemplateOptionsAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2017, 1, 1)
        self.SetEndDate(2017, 3, 1)
        self.SetCash(100000)

        equity = self.AddEquity("GOOG", Resolution.Minute)
        option = self.AddOption("GOOG", Resolution.Minute)
        self.symbol = option.Symbol
   
        # set our strike/expiry filter for this option chain
        option.SetFilter(-30, +30, timedelta(0), timedelta(90))
        # use the underlying equity as the benchmark
        self.SetBenchmark(equity.Symbol)

    def OnData(self,slice):
        if self.Portfolio.Invested: return
    
        for i in slice.OptionChains:
             if i.Key != self.symbol: continue
             chain = i.Value
             call = [x for x in chain if x.Right == OptionRight.Call] 
             put = [x for x in chain if x.Right == OptionRight.Put]


             for i in call:
                   for j in put:
                      if i.Expiry == j.Expiry and i.Strike == j.Strike:
                            if self.Portfolio.Invested: return
                            if i.BidPrice + i.Strike > i.UnderlyingLastPrice + j.AskPrice:
                              self.MarketOrder(i.UnderlyingSymbol, 100) # long the underlying stocks
                              self.MarketOrder(j.Symbol, 1) # long put
                              self.MarketOrder(i.Symbol, -1) # short call

                            elif i.AskPrice + i.Strike < i.UnderlyingLastPrice + j.BidPrice:
                               #quantity = self.CalculateOrderQuantity(self.euqity_symbol,0.6)
                               self.MarketOrder(i.UnderlyingSymbol, -100) # short the underlying stocks
                               self.MarketOrder(j.Symbol, -1) # short put
                               self.MarketOrder(i.Symbol, 1) # long call

    def OnOrderEvent(self, orderEvent):
        self.Log(str(orderEvent))