Overall Statistics
Total Trades
4
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
$4.00
Estimated Strategy Capacity
$430000.00
from QuantConnect.Securities.Option import *

class LogicalFluorescentYellowBeaver(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 9)  # Set Start Date
        self.SetEndDate(2021, 3, 10)
        self.SetCash(100000)  # Set Strategy Cash
        equity = self.AddEquity("TSLA", Resolution.Minute)
        option = self.AddOption(equity.Symbol, Resolution.Minute)
        option.SetFilter(-1, 1, timedelta(1), timedelta(60))
        self.canonical_symbol = option.Symbol
        
        self.option_strategy = None
        self.order_tickets = []
        
        


    def OnData(self, data):
        if self.option_strategy is not None:
            
            # Calculate unrealized profit
            unrealized_profit = sum([self.Portfolio[ticket.Symbol].UnrealizedProfit for ticket in self.order_tickets])
            
            # Determine expiry
            expiry = min([self.Securities[ticket.Symbol].Expiry for ticket in self.order_tickets])
            
            self.Quit(f"Unrealized profit: {unrealized_profit}; Expiry: {expiry}")
        
        for i in data.OptionChains:
            if i.Key == self.canonical_symbol: 
                contracts = [c for c in i.Value]
                strikes = [contract.Strike for contract in contracts]
                expiry = min([contract.Expiry for contract in contracts])
                self.option_strategy = OptionStrategies.BearCallSpread(self.canonical_symbol, 
                                                                      min(strikes), 
                                                                      max(strikes), 
                                                                      expiry)
                self.order_tickets = self.Order(self.option_strategy, 1)