Overall Statistics
Total Trades
3
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
0%
Drawdown
0.000%
Expectancy
0.000
Net Profit
0%
Sharpe Ratio
2.366
Probabilistic Sharpe Ratio
87.592%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
1.00
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
1.449
Tracking Error
0.585
Treynor Ratio
44.997
Total Fees
$2.00
from QuantConnect.Algorithm import *
from QuantConnect.Securities.Option import OptionPriceModels

class BasicTemplateOptionsFilterUniverseAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 17)
        self.SetEndDate(2020, 3, 20)
        self.SetCash(100000)
        
        self.option = self.AddOption("DAL")
        self.AddEquity("DAL", Resolution.Minute)
        
        self.option.SetFilter(-3, +3, 0, 31) 
        
        self.contract = None
        self.done = False
        

    def OnData(self, data):
        if self.done:
            return
        
        if self.contract is not None and self.Portfolio[self.contract.Symbol].Invested:
            self.MarketOrder(self.contract.Symbol, -2)
            self.done = True
            return 
            
        for symbol, chain in data.OptionChains.items():
            contracts = [c for c in chain if c.Right == OptionRight.Call]
            if len(contracts) == 0:
                self.Log("No call contracts expiring today")
                return
            contracts = [c for c in contracts if c.Strike > c.UnderlyingLastPrice]
            sorted_contracts = sorted(contracts, key = lambda x: (x.Strike, x.Expiry), reverse=True)
            self.contract = sorted_contracts[0]
            self.MarketOrder(self.contract.Symbol, 1)