Overall Statistics
Total Trades
10
Average Win
0%
Average Loss
0%
Compounding Annual Return
-21.792%
Drawdown
1.300%
Expectancy
0
Net Profit
-0.860%
Sharpe Ratio
-7.952
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.102
Beta
-5.283
Annual Standard Deviation
0.023
Annual Variance
0.001
Information Ratio
-8.589
Tracking Error
0.023
Treynor Ratio
0.034
Total Fees
$2.50
from datetime import timedelta

class BasicTemplateOptionsAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 12, 1)
        self.SetEndDate(2017, 12, 13)
        self.SetCash(100000)
        self.symbols = []
        for ticker in ["IBM", "AAPL", "EBAY"]:
            option = self.AddOption(ticker)
            self.symbols.append(option.Symbol)
            option.SetFilter(-2, +2, timedelta(0), timedelta(180))
            

    def OnData(self,slice):
        #if self.Portfolio.Invested: return
        for symbol in self.symbols:
            for kvp in slice.OptionChains:
                if kvp.Key == symbol:
                    chain = kvp.Value
                    # we sort the contracts to find at the money (ATM) contract with farthest expiration
                    contracts = sorted(sorted(sorted(chain, 
                        key = lambda x: abs(chain.Underlying.Price - x.Strike)), 
                        key = lambda x: x.Expiry, reverse=True), 
                        key = lambda x: x.Right, reverse=True)
        
                    # if found, trade it
                    if len(contracts) == 0: continue
                    symbol = contracts[0].Symbol
                    if not self.Portfolio[symbol].Invested:
                        self.MarketOrder(symbol, 1)