Overall Statistics
Total Trades
9
Average Win
0.03%
Average Loss
0.00%
Compounding Annual Return
0.250%
Drawdown
0.300%
Expectancy
12.250
Net Profit
0.044%
Sharpe Ratio
0.475
Probabilistic Sharpe Ratio
39.572%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
25.50
Alpha
0.004
Beta
0.008
Annual Standard Deviation
0.004
Annual Variance
0
Information Ratio
1.331
Tracking Error
0.232
Treynor Ratio
0.22
Total Fees
$9.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
AAPL 31XQECR7PGM06|AAPL R735QTJ8XC9X
#region imports
from AlgorithmImports import *
#endregion
# Import statistics library
import statistics

class CrawlingOrangeBull(QCAlgorithm):

    def Initialize(self):
        
        # Set Start Date
        self.SetStartDate(2022, 4, 1)
        
        # Set Strategy Cash
        self.SetCash(100000)
        
        # Add AAPL
        self.AAPL = self.AddEquity("AAPL", Resolution.Minute).Symbol

        # Add option
        option = self.AddOption("AAPL")
        
        # Filter for options expiry date
        option.SetFilter(-20, 20, timedelta(10), timedelta(20))
        
        # Option symbol
        self.AAPL_option = option.Symbol

    def OnData(self, data: Slice):
        
        # If not invested
        if not self.Portfolio.Invested:
            
            # Loop through option chains
            for kvp in data.OptionChains:
                
                # If chain is symbol option chain
                if kvp.Key == self.AAPL_option:

                    # Get value of key:value pair
                    optionchain = kvp.Value
                    
                    # Loop through contracts within chain
                    for contract in optionchain:
                        
                        # Strike price
                        strike = contract.Strike
                        
                        # If strike is lower than current price
                        if strike < self.Securities[self.AAPL].Close:
                            
                            # Get option right
                            right = contract.Right
                            
                            # If right is a put
                            if right == 1:
                                
                                # Sell
                                self.MarketOrder(contract.Symbol, -1, True, "Sell put")
                                    
                                # Break
                                break
        
        # Else
        else:
            
            # Options holdings
            options_holdings = [x for x in self.Portfolio if x.Value.Type == SecurityType.Option]
            
            # Loop through options holdings key-value pair
            for kvp in options_holdings:
                
                # Get value
                option_value = kvp.Value
                
                # Get ID
                option_ID = kvp.Key.ID
                
                # Get option symbol
                option_symbol = option_value.Symbol
                
                # Get expiry
                expiry = option_ID.Date
                
                # If expiry is today
                if expiry.date() == self.Time.date():
                    
                    # Liquidate
                    self.Liquidate(option_symbol)