How to index and iterate through options in the notebook?

Back

I'm having problems indexing/iterating through an options pandas dataframe. 

I had an example that worked a long time ago, and when I tried it today, it doesn't work anymore.

In this example, h['2017-01-20', 785.0, 'Call'] used to work, but now it returns an error.

Iterating through the dataframe only returns the column names.

%matplotlib inline
# Imports
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Jupyter")
AddReference("QuantConnect.Indicators")
from System import *
from QuantConnect import *
from QuantConnect.Data.Market import TradeBar, QuoteBar
from QuantConnect.Jupyter import *
from QuantConnect.Indicators import *
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import pandas as pd

# Create an instance
qb = QuantBook()

goog = qb.AddOption("GOOG")
goog.SetFilter(-2, 2, timedelta(0), timedelta(30))
option_history = qb.GetOptionHistory(goog.Symbol, datetime(2017, 1, 4))
print(option_history.GetStrikes())
print(option_history.GetExpiryDates())
h = option_history.GetAllData()

h.head()

h.index.get_level_values(0)

h['2017-01-20', 785.0, 'Call']

for i in h:print(i)
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.


h.loc[(datetime(2017, 1, 20), 785.0, 'Call')]

This shortcut seems to work

 

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