In [ ]:
## History Test in a Notebook
In [1]:
# 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 datetime import datetime, timedelta
import pandas as pd

# Create an instance
qb = QuantBook()

Selecting Asset Data¶

Checkout the QuantConnect docs to learn how to select asset data.

In [9]:
qb.AddEquity("AAPL")
In [15]:
start = datetime(2014, 7, 1)
end = datetime(2014, 7 , 14)
Out[15]:
datetime.datetime(2014, 7, 1, 0, 0)
In [16]:
history = qb.History("AAPL", start, end, 3)
closes = history.close.unstack(level=0)
closes
Out[16]:
symbol AAPL
time
2014-07-01 09:00:00 88.053685
2014-07-01 10:00:00 88.298409
2014-07-01 11:00:00 88.364297
2014-07-01 12:00:00 88.401946
2014-07-01 13:00:00 88.345472
2014-07-01 14:00:00 88.223109
2014-07-01 15:00:00 88.025447
2014-07-02 09:00:00 88.317234
2014-07-02 10:00:00 88.176047
2014-07-02 11:00:00 88.194872
2014-07-02 12:00:00 87.968973
2014-07-02 13:00:00 88.034860
2014-07-02 14:00:00 87.874848
2014-07-02 15:00:00 87.978385
2014-07-03 09:00:00 88.053685
2014-07-03 10:00:00 88.025447
2014-07-03 11:00:00 88.176047
2014-07-03 12:00:00 88.561958
2014-07-07 09:00:00 89.409081
2014-07-07 10:00:00 89.776167
2014-07-07 11:00:00 89.211419
2014-07-07 12:00:00 89.531443
2014-07-07 13:00:00 89.776167
2014-07-07 14:00:00 90.030304
2014-07-07 15:00:00 90.331503
2014-07-08 09:00:00 90.510340
2014-07-08 10:00:00 89.710280
2014-07-08 11:00:00 88.703146
2014-07-08 12:00:00 89.362019
2014-07-08 13:00:00 89.710280
2014-07-08 14:00:00 89.539914
2014-07-08 15:00:00 89.729105
2014-07-09 09:00:00 89.898530
2014-07-09 10:00:00 90.105604
2014-07-09 11:00:00 90.152666
2014-07-09 12:00:00 89.804405
2014-07-09 13:00:00 89.587918
2014-07-09 14:00:00 89.823230
2014-07-09 15:00:00 89.785580
2014-07-10 09:00:00 88.665496
2014-07-10 10:00:00 88.958224
2014-07-10 11:00:00 89.032582
2014-07-10 12:00:00 89.305544
2014-07-10 13:00:00 89.663218
2014-07-10 14:00:00 89.517324
2014-07-10 15:00:00 89.451437
2014-07-11 09:00:00 89.700868
2014-07-11 10:00:00 90.049129
2014-07-11 11:00:00 89.738518
2014-07-11 12:00:00 89.446731
2014-07-11 13:00:00 89.423200
2014-07-11 14:00:00 89.474968
2014-07-11 15:00:00 89.625568