Back to Lean

Load in our startup script, required to set runtime for PythonNet

Research/BasicQuantBookTemplate.ipynb

2.4.0.11.7 KB
Original Source

Welcome to The QuantConnect Research Page

Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#

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

QuantBook Basics

Start QuantBook

  • Add the references and imports
  • Create a QuantBook instance
python
# Load in our startup script, required to set runtime for PythonNet
%run ../start.py     # %run start.py # in Dev Container
python
# Create an instance
qb = QuantBook()

# Select asset data
spy = qb.AddEquity("SPY")

Historical Data Requests

We can use the QuantConnect API to make Historical Data Requests. The data will be presented as multi-index pandas.DataFrame where the first index is the Symbol.

For more information, please follow the link.

python
# Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution
h1 = qb.History(qb.Securities.Keys, 360, Resolution.Daily)

# Plot closing prices from "SPY" 
h1.loc["SPY"]["close"].plot()

Indicators

We can easily get the indicator of a given symbol with QuantBook.

For all indicators, please checkout QuantConnect Indicators Reference Table

python
# Example with BB, it is a datapoint indicator
# Define the indicator
bb = BollingerBands(30, 2)

# Gets historical data of indicator
bbdf = qb.Indicator(bb, "SPY", 360, Resolution.Daily).data_frame

# drop undesired fields
bbdf = bbdf.drop('standarddeviation', 1)

# Plot
bbdf.plot()