I am trying to create a dynamic universe of options so I created this function that if needed, iterates the stock universe and returns (hopefully) an option contract object. The problem is trying to filter anything out of contracts does not return anything.
def OptionsFilter(self, stock):
contracts = self.OptionChainProvider.GetOptionContractList(stock, self.Time)
puts = [x for x in contracts if x.ID.OptionRight == OptionRight.Put]
puts = sorted(sorted(puts, key = lambda x: x.ID.Date, reverse = True), key = lambda x: x.ID.StrikePrice)
puts = [x for x in puts if 30 < (self.Time - x.ID.Date).days <= 40 and x.ID.StrikePrice <= stock.Price * 0.8]
if puts:
return puts[0]
return
The argument in this function is a stock symbol object. I checked ID.OptionRight attribute of the first item in contracts and it is 0? I also verified it is an option contract and it is. Its symbol value was SNDL 21015C00006000. According to documentation each object in the contracts list is an option contract that should have the attribute self.Right but it doesnt?
Varad Kabade
Hi Yarden,
OptionRight is an enum-type object. In the Enum class, the value of each name constant is an integer by default. So zero signifies call, and one signifies put. Refer to the following tutorial for more information. Note that we also need to subscribe to the selected Contract to receive data for it:
Â
Best,
Varad Kabade
Yarden Gur
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!