Hi,
I am trying to get all strikes in certain expiration, for that purpose I did not define any filtration on strikes, only on expirations, however, when sorting the resulting chain by strike I can see cases that the lowest strike retrievable is higher that the underlying at the same time!
Please advise, thanks.
Mia Alissi
Based on the information provided in the extracts, it seems like you are using the
OptionChainProvider.GetOptionContractList
method to retrieve the option contracts. This method returns a list of option contracts for a given underlying symbol and date.Here is an example of how you can use this method to get all the contracts for a certain expiration and then filter them by strike:
In this code,
expiry
is the earliest expiration date among all the contracts. Thefiltered_symbols
list contains all the contracts that expire on this date.If you want to sort this list by strike, you can do so like this:
Now,
sorted_symbols
is a list of contracts sorted by strike price in ascending order. The first contract in this list is the one with the lowest strike.If the lowest strike retrievable is higher than the underlying at the same time, it might be because there are no contracts with a lower strike available in the market at that time. The availability of option contracts with certain strikes and expirations depends on the market and is not something that can be controlled through the QuantConnect API.
For more information, you can refer to the QuantConnect documentation.
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.
Nathan Sela
Actually I used the following line in OnData:
option_chain = slice.OptionChains.get(self.option_symbol, None)
So I actually am getting the options chain existing in a certain slice.
In using your code:
contract_symbols = self.OptionChainProvider.GetOptionContractList(self.symbol, self.Time)
It does not use the particular slice, so can it be used in OnData to get the current chain?
Mia Alissi
Yes, you can use the
OptionChainProvider.GetOptionContractList
method in theOnData
method to get the current option chain. However, please note that this method returns all the option contracts for the given underlying symbol and date, not just the ones in the current slice.The
slice.OptionChains.get(self.option_symbol, None)
line of code you're using is getting the option chain for theoption_symbol
from the current slice. If the option chain for this symbol is not in the slice, it returnsNone
.Here's how you can use the
OptionChainProvider.GetOptionContractList
method inOnData
:In this code,
contract_symbols
is a list of all option contracts forself.symbol
on the current date (self.Time
). You can then filter and sort this list as needed.Remember that the availability of option contracts in the slice or in the list returned by
GetOptionContractList
depends on the market. If a contract with a certain strike or expiration is not available, it means that there is no such contract in the market at the current time.For more information, you can refer to the QuantConnect documentation.
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.
Nathan Sela
I tested your suggestion to use the OptionChainProvider it provides indeed many options however only from quarterly expirations i.e. once in 3 months…
Mia Alissi
The
OptionChainProvider.GetOptionContractList
method returns all the option contracts available in the market for the given underlying symbol and date. If it's only returning quarterly expirations, it might be because those are the only contracts available in the market at the current time.However, if you're interested in weekly contracts, you might want to check if the underlying symbol has weekly options available. For example, the SPX index has both standard (monthly) and weekly options. The weekly options are denoted with the symbol "SPXW".
Here's an example of how you can request weekly contracts:
In this code,
self.canonical_symbol
is the canonical symbol for the weekly options ofself.symbol
. TheGetOptionContractList
method is then used to get the list of weekly option contracts.Please note that not all underlying symbols have weekly options available. The availability of weekly options depends on the market.
For more information, you can refer to the QuantConnect documentation.
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.
Nathan Sela
Ok
One more question, can the OptionsProvider class provide a list of the options conracts rather then the option symbols you suggested?
Nathan Sela
Or otherwise, how can the Option Contract objects be retrieved from the Option Symbol object?
Mia Alissi
The
OptionChainProvider.GetOptionContractList
method returns a list ofSymbol
objects, not contract objects. EachSymbol
object represents an option contract and contains the details of the contract, such as the underlying symbol, market, option style, option right, strike price, and expiration date.If you want to get the actual contract objects, you can use the
AddOptionContract
method. This method adds the specified option contract to the algorithm and returns theOption
object that represents the contract. Here's an example:In this code,
option
is anOption
object that represents the contract. You can access the properties of the contract through this object.Please note that adding a contract to the algorithm subscribes the algorithm to the data of the contract. If you add a lot of contracts, it might slow down your algorithm.
For more information, you can refer to the QuantConnect documentation.
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.
Mia Alissi
In QuantConnect, the
Symbol
object is used to represent an option contract. TheSymbol
object contains all the details of the contract, such as the underlying symbol, market, option style, option right, strike price, and expiration date.If you have a
Symbol
object, you can access these details like this:In this code,
symbol
is aSymbol
object that represents an option contract. TheUnderlying
,Market
,OptionStyle
,OptionRight
,StrikePrice
, andDate
properties of theSymbol
object give the underlying symbol, market, option style, option right, strike price, and expiration date of the contract, respectively.If you want to get the actual
Option
object that represents the contract, you can use theAddOptionContract
method. This method adds the specified option contract to the algorithm and returns theOption
object that represents the contract. Here's an example:In this code,
option
is anOption
object that represents the contract. You can access the properties of the contract through this object.Please note that adding a contract to the algorithm subscribes the algorithm to the data of the contract. If you add a lot of contracts, it might slow down your algorithm.
For more information, you can refer to the QuantConnect documentation.
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.
Nathan Sela
Is it possible to access the current ask and bid price of the option from the symbol object?
Nathan Sela
Any response to my last question please?
Ashutosh
Hi Nathan, you can get the ask and bid price of options from the Option object.
You can refer to this simple backtest attached.
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.
Nathan Sela
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!