QuantConnect Logo

Welcome to The QuantConnect Research Page¶

Refer to this page for documentation https://www.quantconnect.com/docs#Introduction-to-Jupyter¶

Contribute to this template file https://github.com/QuantConnect/Lean/blob/master/Jupyter/BasicQuantBookTemplate.ipynb¶

QuantBook Basics¶

Start QuantBook¶

  • Add the references and imports
  • Create a QuantBook instance
In [1]:
%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 [4]:
tickers = ["IBM","AAPL","AMZN"]
for i in tickers:
    qb.AddEquity(i, Resolution.Minute)
In [6]:
qb.History(tickers, datetime(2018,2,5), datetime(2018,2,6), Resolution.Minute)
Out[6]:
open high low close volume
symbol time
IBM 2018-02-05 09:31:00 153.087164 153.280945 152.903072 152.922450 7279.0
2018-02-05 09:32:00 152.951517 153.523172 152.893383 153.029029 5349.0
2018-02-05 09:33:00 153.280945 153.813843 153.077475 153.348768 6272.0
2018-02-05 09:34:00 153.077475 153.329390 152.893383 153.184054 211353.0
2018-02-05 09:35:00 153.096853 153.232500 153.029029 153.164676 9677.0
2018-02-05 09:36:00 153.087164 153.416592 153.058097 153.174365 13606.0
2018-02-05 09:37:00 153.145298 153.290634 153.048408 153.184054 10960.0
2018-02-05 09:38:00 153.184054 153.222811 153.087164 153.087164 7329.0
2018-02-05 09:39:00 153.087164 153.087164 152.912761 152.941828 9816.0
2018-02-05 09:40:00 152.951517 152.951517 152.534887 152.631778 21023.0
2018-02-05 09:41:00 152.680223 152.728669 152.505820 152.505820 7871.0
2018-02-05 09:42:00 152.544576 152.641467 152.418619 152.554265 11666.0
2018-02-05 09:43:00 152.505820 152.670534 152.437997 152.573644 10063.0
2018-02-05 09:44:00 152.525198 152.602711 152.321728 152.360484 9850.0
2018-02-05 09:45:00 152.360484 152.534887 152.321728 152.486442 11093.0
2018-02-05 09:46:00 152.399240 152.554265 152.341106 152.554265 10246.0
2018-02-05 09:47:00 152.583333 152.718979 152.457375 152.622089 15515.0
2018-02-05 09:48:00 152.563955 152.651156 152.389551 152.525198 19025.0
2018-02-05 09:49:00 152.534887 152.612400 152.457375 152.602711 9967.0
2018-02-05 09:50:00 152.544576 152.699601 152.525198 152.670534 17031.0
2018-02-05 09:51:00 152.631778 152.680223 152.389551 152.408930 16502.0
2018-02-05 09:52:00 152.447686 152.447686 152.050434 152.098880 37003.0
2018-02-05 09:53:00 152.147325 152.282972 152.069812 152.166703 12340.0
2018-02-05 09:54:00 152.186081 152.273283 152.127947 152.127947 11699.0
2018-02-05 09:55:00 152.157014 152.215148 152.031056 152.137636 20075.0
2018-02-05 09:56:00 152.127947 152.321728 152.079501 152.137636 16518.0
2018-02-05 09:57:00 152.166703 152.292661 152.040745 152.040745 10330.0
2018-02-05 09:58:00 152.069812 152.079501 151.885720 151.885720 15378.0
2018-02-05 09:59:00 151.895409 151.895409 151.701628 151.856653 16301.0
2018-02-05 10:00:00 151.837275 152.166703 151.817897 152.098880 16255.0
... ... ... ... ... ... ...
AMZN 2018-02-05 15:31:00 1416.180000 1417.609000 1403.310000 1405.040000 34969.0
2018-02-05 15:32:00 1404.990000 1408.360000 1401.000000 1401.000000 12375.0
2018-02-05 15:33:00 1401.190000 1411.960000 1400.760000 1411.690000 13136.0
2018-02-05 15:34:00 1411.860000 1412.800000 1406.280000 1411.000000 8916.0
2018-02-05 15:35:00 1411.020000 1411.980000 1407.390000 1408.600000 10022.0
2018-02-05 15:36:00 1408.500000 1410.790000 1405.960000 1407.630000 19363.0
2018-02-05 15:37:00 1407.630000 1408.400000 1400.150000 1400.150000 16552.0
2018-02-05 15:38:00 1400.520000 1406.890000 1400.440000 1401.700000 17944.0
2018-02-05 15:39:00 1401.580000 1405.000000 1397.990000 1399.970000 34277.0
2018-02-05 15:40:00 1399.510000 1401.930000 1397.020000 1398.210000 21884.0
2018-02-05 15:41:00 1398.210000 1398.710000 1393.050000 1394.420000 25218.0
2018-02-05 15:42:00 1394.570000 1402.250000 1393.520000 1399.080000 19525.0
2018-02-05 15:43:00 1399.190000 1402.910000 1398.500000 1401.000000 25095.0
2018-02-05 15:44:00 1401.210000 1401.880000 1395.990000 1398.000000 18096.0
2018-02-05 15:45:00 1398.220000 1401.880000 1397.300000 1399.990000 17573.0
2018-02-05 15:46:00 1399.990000 1400.430000 1396.000000 1396.810000 23249.0
2018-02-05 15:47:00 1397.030000 1399.730000 1395.560000 1398.420000 21761.0
2018-02-05 15:48:00 1397.490000 1398.390000 1391.500000 1391.500000 22026.0
2018-02-05 15:49:00 1391.580000 1396.000000 1391.450000 1394.870000 25729.0
2018-02-05 15:50:00 1394.980000 1395.460000 1388.600000 1389.330000 39888.0
2018-02-05 15:51:00 1389.450000 1396.760000 1388.000000 1391.000000 28067.0
2018-02-05 15:52:00 1390.190000 1390.560000 1388.000000 1388.010000 33661.0
2018-02-05 15:53:00 1388.010000 1391.010000 1385.600000 1387.663000 33108.0
2018-02-05 15:54:00 1387.340000 1391.420000 1386.670000 1388.280000 37256.0
2018-02-05 15:55:00 1388.770000 1390.000000 1384.580000 1385.620000 33097.0
2018-02-05 15:56:00 1385.420000 1392.600000 1384.750000 1389.540000 30361.0
2018-02-05 15:57:00 1389.550000 1398.500000 1387.990000 1397.990000 55970.0
2018-02-05 15:58:00 1398.010000 1403.070000 1396.000000 1403.030000 61674.0
2018-02-05 15:59:00 1402.990000 1403.250000 1393.540000 1394.810000 62889.0
2018-02-05 16:00:00 1394.890000 1399.550000 1388.810000 1390.000000 78805.0

1170 rows × 5 columns