| Overall Statistics |
|
Total Orders 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Start Equity 100000 End Equity 100000 Net Profit 0% Sharpe Ratio 0 Sortino 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 Portfolio Turnover 0% |
from AlgorithmImports import *
class ListQQQODTEOptions(QCAlgorithm):
def Initialize(self):
# Set the backtest time period and initial cash
self.SetStartDate(2024, 11, 21)
self.SetEndDate(2024, 11, 21) # Single day backtest
self.SetCash(100000)
# Add QQQ ETF
self.qqq = self.AddEquity("QQQ", Resolution.Minute)
# Add QQQ options
qqq_options = self.AddOption("QQQ", Resolution.Minute)
qqq_options.SetFilter(lambda u: u.Strikes(-999, 999)) # Include all strikes
self.qqq_options_symbol = qqq_options.Symbol
# Schedule to log options expiring today at 3:00 PM
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(15, 0), self.ListODTEOptions)
def ListODTEOptions(self):
"""Logs QQQ ODTE options available at 3:00 PM."""
# Fetch the current QQQ price
qqq_price = self.qqq.Price
if qqq_price == 0:
self.Debug("QQQ price is unavailable.")
return
# Fetch the option chain
chain = self.CurrentSlice.OptionChains.GetValue(self.qqq_options_symbol)
if chain is None or not list(chain): # Convert chain to list to check if it's empty
self.Debug("No options chain available.")
return
# Filter options expiring today (ODTE)
today = self.Time.date()
odte_options = [option for option in chain if (option.Expiry.date() - today).days == 0]
if not odte_options:
self.Debug(f"No ODTE options available on {today}.")
return
# Log all ODTE options
self.Debug(f"QQQ ODTE Options at 3:00 PM on {today}:")
for option in odte_options:
self.Debug(f"Strike: {option.Strike}, Type: {option.Right}, Expiry: {option.Expiry}, "
f"Price: {option.LastPrice}, Bid: {option.BidPrice}, Ask: {option.AskPrice}")
def OnData(self, slice):
# OnData is required but not used for this specific task
pass