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
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
from QuantConnect.Securities.Option import OptionPriceModels
from datetime import timedelta

class LongStrangleAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 2)
        self.SetEndDate(2020, 1, 14)
        self.SetCash(100000)
        
        equity = self.AddEquity("NVDA", Resolution.Minute)
        equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
        
        option = self.AddOption(equity.Symbol, Resolution.Minute)
        self.symbol = option.Symbol
        
        option.SetFilter(-1, 1, timedelta(1), timedelta(90)) 
        option.PriceModel = OptionPriceModels.CrankNicolsonFD()
        
        self.SetWarmUp(10, Resolution.Daily) 
        self.show = True
        
        
    def OnData(self,slice):
        if self.IsWarmingUp: return
       
        for i in slice.OptionChains:
            if i.Key != self.symbol: continue
            optionchain = i.Value
            
            options_by_type = [x for x in optionchain if x.Right == OptionRight.Call]
            contracts = sorted(options_by_type, key = lambda x: abs(x.Greeks.Delta), reverse=True)
            if len(contracts) == 0: return None #no option was found 
            
            if self.show:
                self.show = False
                self.PrintOptionContract(contracts[0])

            
    def PrintOptionContract(self, contract):
        self.Quit(contract.Symbol.Value + ", strike: " + str(contract.Strike) + \
                ", Gamma" + str(contract.Greeks.Gamma) + \
                ", Rho" + str(contract.Greeks.Rho) + \
                ", Delta: " + str(contract.Greeks.Delta) + \
                ", Vega: " + str(contract.Greeks.Vega) +\
                ", IV: " + str(contract.ImpliedVolatility) + \
                ", AskPrice: " + str(contract.AskPrice) + \
                ", Underlying Price: " + str(contract.UnderlyingLastPrice))


    def OnEndOfDay(self):
        self.show = True