Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-5.682
Tracking Error
0.125
Treynor Ratio
0
Total Fees
$0.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, 4, 16)
        self.SetCash(100000)
        
        self.equity = self.AddEquity("AAPL", Resolution.Minute)
        self.equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.equity.VolatilityModel = StandardDeviationOfReturnsVolatilityModel(30);
        
        self.SetWarmup(30, Resolution.Daily)

        self.contract = None
        
        
    def OnData(self, data):

        if self.IsWarmingUp:
            return

        if self.contract is None:
            self.OptionsFilter(data)
            return

        if data.Time.hour == 12 and data.Time.minute == 0:

            for symbol, chain in data.OptionChains.items():
                self.contract = [c for c in chain if c.Symbol == self.contract.Symbol][0]

                self.Plot("Price", "Theoretical", self.contract.TheoreticalPrice)
                self.Plot("Volatility", "Value", self.equity.VolatilityModel.Volatility)
                self.Plot("Delta", "Value", self.contract.Greeks.Delta)

                    
    def OptionsFilter(self, data):
        contract_symbols = self.OptionChainProvider.GetOptionContractList(self.equity.Symbol, data.Time) 
        contracts = [OptionContract(symbol, self.equity.Symbol) for symbol in contract_symbols]
        contracts = sorted(contracts, key=lambda x: x.Expiry, reverse=True)
        self.contract = contracts[0]
        
        ## Use AddOptionContract() to subscribe the data for a specified contract
        option = self.AddOptionContract(self.contract.Symbol, Resolution.Minute)
        option.PriceModel = OptionPriceModels.BinomialTian() # CrankNicolsonFD()