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
-3.207
Tracking Error
0.091
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class TestSPXIndexOptionWeeklyAlgorithm(QCAlgorithm):

   def Initialize(self):
      # Backtesting parameters
      self.SetStartDate(2021, 1, 11)
      self.SetEndDate(2021, 1, 22)
      self.SetCash(1000000)
      
      # Index Ticker Symbol
      self.ticker = "SPX"
      # Time Resolution
      self.timeResolution = Resolution.Minute   # Resolution.Minute .Hour .Daily
            
      # Add the underlying Index
      index = self.AddIndex(self.ticker, self.timeResolution)
      index.SetDataNormalizationMode(DataNormalizationMode.Raw)
      self.underlyingSymbol = index.Symbol
      
      # Set Security Initializer (This does not seem to solve the issue with the benchmark below)
      self.SetSecurityInitializer(self.security_initializer)

      # -----------------------------------------------------------------------------
      # Scheduled function: every day, 25 minutes after the market open
      # -----------------------------------------------------------------------------
      self.Schedule.On(self.DateRules.EveryDay(self.underlyingSymbol)
                       , self.TimeRules.AfterMarketOpen(self.underlyingSymbol, 25)
                       , Action(self.openPosition)
                       )

   def security_initializer(self, security):
      # * SecurityType.Index & SecurityType.IndexOption
      security.SetDataNormalizationMode(DataNormalizationMode.Raw)
      security.SetMarketPrice(self.GetLastKnownPrice(security))
            
   
   def openPosition(self):
   
      self.Debug("Entering method openPosition")
      
      # Get the option contracts
      contracts = self.OptionChainProvider.GetOptionContractList(self.underlyingSymbol, self.Time)
      # Exit if there are no contracts
      if not contracts:
          self.Debug("OptionChainProvider returned no contracts!")
          return
      
      # Log the number of contracts that were found
      self.Debug(" -> Found " + str(len(contracts)) + " contracts in the option chain!")
      
      # Get the list of Expiration Dates in the option chain
      expiry_list = sorted(set([contract.ID.Date.date() for contract in contracts]))
      self.Debug("   -> Expiry dates: " + str(expiry_list))
      

   def OnData(self, slice):
      pass