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
-11.629
Tracking Error
0.006
Treynor Ratio
0
Total Fees
$0.00
from QuantConnect.Securities.Option import OptionPriceModels

class BasicTemplateOptionsFilterUniverseAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        self.SetEndDate(2019, 1, 2)
        self.SetCash(100000)
        
        self.alpha = MyAlphaModel()
        self.AddAlpha(self.alpha)
        
        self.option = self.AddOption("AAPL")
        
        self.option.SetFilter(-1, +1, 15, 60) 
        
        # set the pricing model for Greeks and volatility
        # find more pricing models https://www.quantconnect.com/lean/documentation/topic27704.html
        self.option.PriceModel = OptionPriceModels.CrankNicolsonFD()
        # set the warm-up period for the pricing model
        self.SetWarmUp(TimeSpan.FromDays(4))
    
    def OnEndOfDay(self):
        self.alpha.shown = False

class MyAlphaModel(AlphaModel):
    shown = False
    
    def Update(self, algorithm, slice):

        if algorithm.IsWarmingUp or algorithm.Portfolio.Invested:
            return []
        
        if self.shown:
            return []
        self.shown = True
        
        for symbol, chain in slice.OptionChains.items():
            for contract in chain:
                d = contract.Greeks.Delta
                g = contract.Greeks.Gamma
                l = contract.Greeks.Lambda
                r = contract.Greeks.Rho
                t = contract.Greeks.Theta
                v = contract.Greeks.Vega
                algorithm.Log(f"\nDelta: {d}\nGamma: {g}\nLambda: {l}\nRho: {r}\nTheta: {t}\nVega: {v}")
                
        return []