Overall Statistics
Total Trades
5
Average Win
0.74%
Average Loss
-0.87%
Compounding Annual Return
-24.701%
Drawdown
1.600%
Expectancy
-0.073
Net Profit
-0.607%
Sharpe Ratio
-3.797
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.85
Alpha
-0.641
Beta
26.858
Annual Standard Deviation
0.057
Annual Variance
0.003
Information Ratio
-4.092
Tracking Error
0.057
Treynor Ratio
-0.008
Total Fees
$5.00
from datetime import timedelta

### OCA (One Order Cancels All) Example for Options
class bracketOrderOptionExample(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 1, 1)
        self.SetEndDate(2016, 1, 8)
        self.SetCash(100000)

        option = self.AddOption("GOOG",Resolution.Minute)
        self.option_symbol = option.Symbol

        # set our strike/expiry filter for this option chain
        option.SetFilter(self.UniverseFunc)
        
        self.entry_ticket = None

        
    def OnData(self,slice):
        
        if not self.Portfolio.Invested and self.entry_ticket is None:
            for i in slice.OptionChains:
                chain = i.Value
                call = [i for i in chain if i.Right == OptionRight.Call]
                contracts =  sorted(sorted(call, key=lambda x: x.Expiry, reverse=True),
                                                key=lambda x: abs(x.UnderlyingLastPrice - x.Strike))
                atm_contract = contracts[0]
                
                # Buy ATM Call Option Contract
                if len(contracts) == 0: continue
                symbol = contracts[0].Symbol
                
                
                price = self.Securities[symbol].Price
                
                # Place limit order below market price. Wait for rebound to buy 
                self.entry_ticket = self.LimitOrder(symbol, 1, price*(1-0.05))

                
                
    def OnOrderEvent(self, orderEvent):
        if orderEvent.Status != OrderStatus.Filled:
            return
        
        if self.entry_ticket is not None:
            # When entry order is filled, place TP and SL orders
            if orderEvent.OrderId == self.entry_ticket.OrderId:
                price = orderEvent.FillPrice
                self.LimitOrder(orderEvent.Symbol, -1, price*1.2)
                self.StopMarketOrder(orderEvent.Symbol, -1, price*0.8)
            # Otherwise, one of the exit orders was filled, so cancel the open orders
            else:
                self.Transactions.CancelOpenOrders(orderEvent.Symbol)
                self.entry_ticket = None                                    
                
                    
    def UniverseFunc(self, universe):
        # include weekly contracts
        return universe.Expiration(TimeSpan.FromDays(60),TimeSpan.FromDays(90)).Strikes(-2,2)