Currently we have a few ways to use QuantConnect research notebooks:
- Lean CLI (Recommended)
- Install locally and run directly on your OS.
This document will cover the setup, getting started, and known issues.
Below we cover how to get setup with our two options listed above.
Our research docker image has been integrated with Lean CLI to streamline the process and allow user to use their cloud and local projects in the research environment. Please refer to Lean CLI documentation here on how to get started.
Lean CLI research specific documentation is found here.
We highly recommend using Lean CLI with docker for research but below in Running Jupyter Locally we cover how to install and prepare the environment on your personal desktop.
Note: we recommend using the above approach with our Docker container, where the setup and environment is tested and stable.
Before we enable Jupyter support, follow Lean installation and Python installation to get LEAN running Python algorithms on your machine. Then be sure to build Lean at least once before the following.
1. Installation:
- Install JupyterLab:
pip install jupyterlab
- Install QuantConnect Python API
pip install quantconnect
- Install pythonnet/clr-loader
pip install clr-loader
2. Run Jupyter:
- Run Jupyter from the command line
cd Lean/Launcher/bin/Debug
jupyter lab
When using C# for research notebooks it requires that you load our setup script CSX file Initialize.csx
into your notebook. This will load our QuantConnect libraries into your C# Kernel. In both docker setups, the file is one directory above the notebooks dir. Be sure to use the following line in your first cell to load in this csx file:
#load "../Initialize.csx"
After this the environment is ready to use; take a look at our reference notebook KitchenSinkCSharpQuantBookTemplate.ipynb
for an example of how to use our QuantBook
interface!
Note: All Lean namespaces you want to use in your notebook need to be directly added via using
statements.
With Python we have a setup script that will automatically load QuantBooks libraries into the Python kernel so there is no need to import them. In our docker image the script should run automatically, but locally you will need to call %run "start.py"
in the first cell.
You notebook is ready to use; take a look at our reference notebook KitchenSinkQuantBookTemplate.ipynb
for an example of how to use our QuantBook
interface!
Both of our setup scripts for Python & C# include a instantiated Api
object under the variable name api
. Before you can use this api object to interact with the cloud you must edit your config in the root of your Notebook directory. Once this has been done once, it does not need to be done again.
In config.json
add the following entries with your respective values
job-user-id: 12345, // Your id here
api-access-token: "token13432", // Your api token here
Once this has been done, you may restart your kernel and begin to use the api
variable.
Reference our examples mentioned above for practical uses of this object.
When you are done with the research environment be sure to stop the container with Docker Dashboard or via Docker CLI.
For most users this will not be necessary, simply use docker pull quantconnect/research
to get the latest image.
docker build -t quantconnect/research - < DockerfileJupyter
will build a new docker image using the latest version of lean. To build from particular tag of lean a build arg can be provided, for example --build-arg LEAN_TAG=8631
.
-
Python research is extremely dependent on the
start.py
script as it is responsible for assigning core clr as the runtime for PythonNet and clr-loader to use for C# library. For local use where the script is not launched automatically by Jupyter, one must call%run "start.py"
in their first notebook cell for research to work properly. Note that the location ofstart.py
is in the launcher bin directory so you may have to use../start.py
or specify the full path. -
C# research latest kernel no longer supports using statements outside of the notebook context, meaning that
#load ./QuantConnect.csx
no longer applies QC namespaces to the notebook out of the box. Therefore one must specify the namespace directly in a cell. Our default notebooks include these statements as examples. -
Python can sometimes have issues when paired with our quantconnect stubs package on Windows. This issue can cause modules not to be found because
site-packages
directory is not present in the python path. If you have the required modules installed and are seeing errors about them not being found, please try the following steps:- remove stubs -> pip uninstall quantconnect-stubs
- reinstall stubs -> pip install quantconnect-stubs