As I work on deploying my Options strategies, I've encountered a crucial need for a given contract's Bid and Ask price. This data is pivotal for the success of my strategy. I've been using the Daily resolution and extracting data using the OptionChainProvider method.
After meticulously slicing, dicing, and subscribing to the option chain data, I extracted other parameters, such as date and strike price. However, the bid/ask price continues to elude me, always returning as zero.
I have tried ‘Hour’ and ‘Minute’ resolutions without luck. Below is the overall sequence of my code for review.
The code below gets the following error message:
“‘Runtime Error: 'Symbol' object has no attribute 'Symbol' at options_filter callsell_ask = self.Securities[contract.Symbol].AskPrice”
However, if I use it without ‘Symbol’, it gets 0 value.
I appreciate any help resolving the problem.
def Initialize(self):
self.SetStartDate(2023, 1, 1)
self.SetEndDate(2023, 8, 31)
self.SetCash(100000)
self.equity = self.AddEquity("AAPL", Resolution.Daily)
self.symbol = self.equity.Symbol
def option_filter(self, data)
self.contract_symbols = self.OptionChainProvider.GetOptionContractList(self.symbol, data.Time)
callsell = [i for i in self.contract_symbols if i.ID.OptionRight == OptionRight.Call]
# subscribe these contracts
For contract in callsell:
self.AddOptionContract(contract, Resolution.Daily)
if self.Securities[contract.Symbol].HasData:
callsell_bid = self.Securities[contract.Symbol].BidPrice
callsell_ask = self.Securities[contract.Symbol].AskPrice
Mia Alissi
Sources: Handling Data - QuantConnect.com, US Equity Options - QuantConnect.com, Using Data - QuantConnect.com, Greeks and IV Implementation, Individual Contracts - QuantConnect.com
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Mitul Shah
Thanks for your quick response, Mia.
If we use lower resolutions (Daily) for self.add_equity and higher resolution (Minute) for add_option_contract, shouldn’t it create an internal conflict for the algorithm and generate unreliable results?
Mitul Shah
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!