Overall Statistics
Total Trades
86
Average Win
0.65%
Average Loss
-0.57%
Compounding Annual Return
-36.983%
Drawdown
9.000%
Expectancy
-0.134
Net Profit
-3.810%
Sharpe Ratio
-1.848
Probabilistic Sharpe Ratio
18.099%
Loss Rate
60%
Win Rate
40%
Profit-Loss Ratio
1.14
Alpha
0.393
Beta
-1.954
Annual Standard Deviation
0.19
Annual Variance
0.036
Information Ratio
-3.054
Tracking Error
0.24
Treynor Ratio
0.18
Total Fees
$192.50
Estimated Strategy Capacity
$8000.00
Lowest Capacity Asset
IBM 30OQNYYJCY7OM|IBM R735QTJ8XC9X
from datetime import timedelta

class BasicTemplateOptionsAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 11, 1)
        self.SetEndDate(2017, 12, 1)
        self.SetCash(100000)
        self.entryTime = self.UtcTime
        self.symbols = []
        for ticker in ["IBM", "AAPL"]:
            option = self.AddOption(ticker)
            self.symbols.append(option.Symbol)
            option.SetFilter(1, 4, timedelta(2), timedelta(180))
            symbol = self.AddEquity(ticker, Resolution.Minute).Symbol
            self.__change = self.ROCP(ticker, 1440, Resolution.Minute) #find % increase in last 24 hours

    def OnData(self,slice):
        option_invested = [x.Key for x in self.Portfolio if x.Value.Invested and x.Value.Type==SecurityType.Option] # check if we already have open options postiions
        if option_invested: # check if we have an open option position
            if (self.UtcTime - self.entryTime) >= timedelta(hours = 23.8): #Sell after set hours
                self.Liquidate(option_invested[0], "Sold")
        if self.Time.minute == 30 and self.Time.hour == 13: #check if time is 1030
            for symbol in self.symbols:
                self.Log(str(self.__change) + str(symbol))
                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=False), 
                            key = lambda x: x.Right, reverse=True)
            
                        # if found, trade it
                        if len(contracts) == 0: continue
                        symbol = contracts[0].Symbol
                        self.SetHoldings(symbol, 0.02)
                        self.entryTime = self.UtcTime
                        #self.Log(str(self.__change) + str(symbol) + "second")