In [15]:
%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.Custom 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()
In [16]:
goog = qb.AddOption("GOOG")
goog.SetFilter(lambda universe: universe.IncludeWeeklys().Strikes(-1, +1).Expiration(timedelta(0), timedelta(7)))
In [18]:
option_history = qb.GetOptionHistory(goog.Symbol, datetime(2018, 1, 19))
print option_history.GetStrikes()
print option_history.GetExpiryDates()
h7 = option_history.GetAllData()
[1132.5, 1135.0, 1137.5, 1130.0, 1127.5]
[datetime.datetime(2018, 1, 19, 0, 0), datetime.datetime(2018, 1, 26, 0, 0)]
In [21]:
h7 = option_history.GetAllData()
h7.index.get_level_values('time')
Out[21]:
DatetimeIndex(['2018-01-18 09:31:00', '2018-01-18 09:32:00',
               '2018-01-18 09:33:00', '2018-01-18 09:34:00',
               '2018-01-18 09:35:00', '2018-01-18 09:36:00',
               '2018-01-18 09:37:00', '2018-01-18 09:38:00',
               '2018-01-18 09:39:00', '2018-01-18 09:40:00',
               ...
               '2018-01-18 15:51:00', '2018-01-18 15:52:00',
               '2018-01-18 15:53:00', '2018-01-18 15:54:00',
               '2018-01-18 15:55:00', '2018-01-18 15:56:00',
               '2018-01-18 15:57:00', '2018-01-18 15:58:00',
               '2018-01-18 15:59:00', '2018-01-18 16:00:00'],
              dtype='datetime64[ns]', name=u'time', length=8190, freq=None)
In [22]:
option_history = qb.GetOptionHistory(goog.Symbol, datetime(2018, 1, 20))
print option_history.GetStrikes()
print option_history.GetExpiryDates()
h7 = option_history.GetAllData()
[]
[]
In [ ]: