Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-7.812%
Drawdown
0.800%
Expectancy
0
Net Profit
-0.348%
Sharpe Ratio
-1.957
Probabilistic Sharpe Ratio
23.431%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.32
Beta
0.139
Annual Standard Deviation
0.039
Annual Variance
0.002
Information Ratio
-9.699
Tracking Error
0.189
Treynor Ratio
-0.55
Total Fees
$1.00
from QuantConnect.Algorithm import *
from QuantConnect.Securities.Option import OptionPriceModels

class BasicTemplateOptionsFilterUniverseAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        self.SetEndDate(2019, 1, 16)
        self.SetCash(100000)
        
        self.option = self.AddOption("AAPL")
        self.option.SetFilter(-1, +1, 14, 60) 
        
        self.option.PriceModel = OptionPriceModels.BinomialTian()
        self.SetWarmUp(30, Resolution.Daily)
        self.done = False
        
        
    def OnData(self,slice):

        if self.IsWarmingUp:
            return

        for chain in slice.OptionChains:
            for symbol, chain in slice.OptionChains.items():
                if not self.done:
                    contracts = [c for c in chain if c.Right == OptionRight.Call]
                    sorted_contracts = sorted(contracts, key = lambda x: x.Expiry, reverse=True)
                    self.contract = sorted_contracts[0]
                    self.MarketOrder(self.contract.Symbol, 1)
                    self.done = True
                else:
                    contract = [c for c in chain if str(c) == str(self.contract)]
                    if len(contract) == 0:
                        return
                    contract = contract[0]
                    self.Plot("Price", "Theoretical", contract.TheoreticalPrice)
                    self.Plot("Volatility", "Value", self.Securities[symbol.Underlying].VolatilityModel.Volatility)
                    self.Plot("Delta", "Value", contract.Greeks.Delta)