QuantConnect: Getting Started with a Jupyter QuantBook

QuantConnect provides a great feature that allows users to perform research and generate backtest ideas. Jupyter notebooks, known as “QuantBooks” are available and be used to interactively explore data. This article will cover how to open a “QuantBook” on Quantconnect and start playing with some OHLC data.

What is a QuantBook?

It is simply a Jupter notebook that has access to QuantConnect’s API and Data. This makes it a great tool for exploring the API and performing some analysis on historical data without having to run backtests. For more information on Jupyter notebooks see here:

https://jupyter.org/

How do I use one? 

This is the first potential stumbling block. The official documentation does not really tell you how to launch a QuantBook. Fortunately, once you know how, it is quite easy. 

Disclaimer: QuantConnect actively develop and improve their site often. This is partly why the number of step by step QuantConnect articles on this site has plateaued in recent months. They can be out of date rather quickly. It is a good thing though! They are actively improving all the time. With this in mind, the instructions below are correct at the time of writing. 

Each algorithm can have one or more QuantBooks contained within it! This makes sense as you might want to perform research which is dedicated to that strategy. As you now might be able to guess, that means we find the QuantBook within the algorithm development environment! 

The Steps

First, open the “Algorithm Lab” from the top level menu and then select “Create Algorithm”

Creating a new algorithm so we can access a QuantBook

Next, you can build a template for the algorithm using some pre-defined code chunks. However, for the basis of this tutorial, we will just create a “basic template algorithm”. 

You should now see a development environment that looks something like the following image. Notice that there is a Files section in the left pane. Within this there is research.ipynb section. This is it! 

If you click on research.ipynb it will load a Jupyter notebook will launch containing a basic example showing how to plot Bollinger bands over the SPY.  

Creating a QuantBook

You can also create additional notebooks for the project by clicking on “Add New Notebook”. 

Playing with the data

A QuantBook will allow you to explore the data and framework without needing to constantly run backtests. This can be invaluable if you are developing an alpha and you don’t want to increase your backtest count just look at data or run dir() on an object. 

The default example takes care of grabbing some data for us. 

Let’s build upon this and use the historical data to plot a candlestick chart. 

First, import mplfinance, a module which will help us to conveniently plot financial data. 

Next, reduce the amount of historical data to 30 days. Reducing the amount of candles will help use see the candlesticks a bit more clearly at the end of the tutorial. 

All data is returned as a pandasdataframe. Pandas is very popular data analysis library that is widely used in data science. It has a lot of convenience functions for working with large datasets. For more information see:

https://pandas.pydata.org/

Now we have our data, we need to extract the OHLC data for SPY out of the dataframe. That might sound unintuitive at first. However, it is because we can actually request data for multiple instruments at the same time and so the dataframe may have more than one instrument within it. 

Finally, we should rename and re-arrange the order of the columns as the QuantConnect provides data in the order close, high, low, open, volume but matplotlib would like Open, High, Low, Close and Volume.

We are now ready to plot with:

And you should see something like this!

 

QuantBook Candlestick chart

 

Find This Post Useful?

If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny. 

Backtest Rookies is a registered with Brave publisher!

Brave users can drop us a tip.

Alternatively, support us by switching to Brave using this referral link and we will receive some BAT! 


https://brave.com/bac691

Referral Link

Enjoying the content and thinking of subscribing to Tradingview? Support this site by clicking the referral link before you sign up! 

https://tradingview.go2cloud.org/SHpB


Donate with PayPal using any payment method you are comfortable with! 


3HxNVyh5729ieTfPnTybrtK7J7QxJD9gjD

0x9a2f88198224d59e5749bacfc23d79507da3d431

M8iUBnb8KamHR18gpgi2sSG7jopddFJi8S