Verify the 'History' method returns a dataframe. Also verify what forms the method can be called with.
# Imports - not certain all these are required. from clr import AddReference AddReference("System") AddReference("QuantConnect.Common") AddReference("QuantConnect.Jupyter") from System import * from QuantConnect import * from QuantConnect.Data.Market import TradeBar, QuoteBar from QuantConnect.Jupyter import * from datetime import datetime, timedelta import pandas as pd # Create an instance qb = QuantBook()
<QuantConnect.Securities.Equity.Equity at 0x7fc3719d66d0>
First use the plain form with just the number of days (in this case) of data we want. This should return data for all assets with data subscriptions (eg added with the 'AddEquity' method as above). This should return data for AAPL and IBM.
# Gets the last 10 days historical data for the subscribed assets. history_plain_form = qb.History(10)
# Let's see what we've got history_plain_form
# Looks like a Dataframe of the data but let's be sure. type(history_plain_form)
# Good. It's a Dataframe. # Note that this form does NOT seem to work in an algorithm # Let' try another form where we specify a list of assets history_list_form = qb.History(['AAPL', 'IBM'], 10)
TypeErrorTraceback (most recent call last) <ipython-input-10-295d4fd660c4> in <module>() 2 # Note that this form does NOT seem to work in an algorithm 3 # Let' try another form where we specify a list of assets ----> 4 history_list_form = qb.History(['AAPL', 'IBM'], 10) TypeError: No method matches given arguments
# OOPS. This form does NOT work in notebooks. # However, it does in an algorithm. Which is good because we often just have a list of assets.
# Also doesn't work with a variable list my_list = ['AAPL', 'IBM'] history_list_form = qb.History(my_list, 10)
TypeErrorTraceback (most recent call last) <ipython-input-12-69be1fcd7b91> in <module>() 1 # Also doesn't work with a variable list 2 my_list = ['AAPL', 'IBM'] ----> 3 history_list_form = qb.History(my_list, 10) TypeError: No method matches given arguments
# Oh well....