Back

Using Options in Research Environment

I'm working through the tutorial for using options in QuantConnect and am stuck on getting the option chain from an options object. The code below is from the tutorial and I'm trying to adapt it into a ipynb file so I can explore the data:

def OnData(self,slice):
for kvp in slice.OptionChains:
if kvp.Key != self.symbol:
continue
optionchain = kvp.Value
df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
index=[x.Symbol.Value for x in optionchain],
columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price'])
self.Log(f"Underlying price: {optionchain.Underlying.Price}\n{df}")

I'd like to follow the tutorial to get a dataframe of data from the optionschain variable and am erroring on the slice class. Am I missing something?

My code so far...

101680_1589310236.jpg

 

Update Backtest







0

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.


Hi Iwan,

The main issue here is that you try to use slice, which is Engine attribute in research environment (as I understand). Instead, you have to pull history of prices and work on them. I also struggled a bit and here is the topic I did to show a template how it worked for me... Hope that'll help.

https://www.quantconnect.com/forum/discussion/8131/options-in-research-environment-primer/p1

 

0

Update Backtest





0

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.


Loading...

This discussion is closed