Research

Getting Started

Running a jupyter notebook cell

Introduction

The Research Environment is a Jupyter notebook-based, interactive commandline environment where you can access your local data or our cloud data through the QuantBook class. The environment supports both Python and C#. If you use Python, you can import code from the code files in your project into the Research Environment to aid development.

Before you run backtests, we recommend testing your hypothesis in the Research Environment. It's easier to perform data analysis and produce plots in the Research Environment than in a backtest.

Before backtesting or live trading with machine learning models, you may find it beneficial to train them in the Research Environment, save them in the Object Store, and then load them from the Object Store into the backtesting and live trading environment

In the Research Environment, you can also use the QuantConnect API to import your backtest results for further analysis.

Note: This chapter is an introduction to the Research Environment for Local Platform. For more comprehensive information on using research notebooks, see our dedicated Research Environment documentation.

Example

The following snippet demonstrates how to use the Research Environment to plot the price and Bollinger Bands of the S&P 500 index ETF, SPY:

The following snippet demonstrates how to use the Research Environment to print the price of the S&P 500 index ETF, SPY:

// Load the required assembly files and data types
#load "../Initialize.csx"
#load "../QuantConnect.csx"
using QuantConnect;
using QuantConnect.Data;
using QuantConnect.Algorithm;
using QuantConnect.Research;

// Create a QuantBook
var qb = new QuantBook();

// Create a security subscription
var symbol = qb.AddEquity("SPY").Symbol;

// Request some historical data
var history = qb.History(symbol, 70, Resolution.Daily);

foreach (var tradeBar in history)
{
    Console.WriteLine($"{tradeBar.EndTime} :: {tradeBar.ToString()}");
}
# Create a QuantBook
qb = QuantBook()

# Create a security subscription
spy = qb.AddEquity("SPY")

# Request some historical data
history = qb.History(qb.Securities.Keys, 360, Resolution.Daily)

# Calculate the Bollinger Bands
bbdf = qb.Indicator(BollingerBands(30, 2), spy.Symbol, 360, Resolution.Daily)

# Plot the data
bbdf.drop('standarddeviation', 1).plot()
Bollinger Bands plotting in research environment Historical minute data of SPY

Open Notebooks

Local Platform provides multiple deployment targets to enable you to open notebooks on-premise and in QuantConnect Cloud. Each new project you create contains a notebook file by default. Follow these steps to open it:

  1. Open the project.
  2. In the left navigation menu, click the Local platform explorer icon Explorer icon.
  3. In the Explorer panel, expand the QC (Workspace) section.
  4. Click the Research.ipynbresearch.ipynb file.

Run Notebook Cells

Notebooks are a collection of cells where you can write code snippets or MarkDown. To execute a cell, press Shift+Enter.

Python jupyter notebook interface C# jupyter notebook interface

The following describes some helpful keyboard shortcuts to speed up your research:

Keyboard ShortcutDescription
Shift+EnterRun the selected cell.
aInsert a cell above the selected cell.
bInsert a cell below the selected cell.
xCut the selected cell.
vPaste the copied or cut cell.
zUndo cell actions.

Stop Nodes

Follow these steps to stop a research node:

  1. If you opened the research notebook on Local Platform, close the notebook file.
  2. In the Resources panel, click the stop button next to the research node you want to stop.
  3. In the Visual Studio Code window, click Yes.

Add Notebooks

Follow these steps to add notebook files to a project:

  1. Open the project.
  2. In the right navigation menu, click the Local lab explorer icon Explorer icon.
  3. In the Explorer panel, expand the QC (Workspace) section.
  4. Click the Add new file icon New File icon.
  5. Enter fileName.ipynb.
  6. Press Enter.
Adding a research notebook in Python development environment Adding a research notebook in C Sharp development environment

Rename Notebooks

Follow these steps to rename a notebook in a project:

  1. Open the project.
  2. In the left navigation menu, click the Explorer icon.
  3. In the Explorer panel, right-click the notebook you want to rename and then click Rename.
  4. Enter the new name and then press Enter.
Warning: Undefined variable $videoLink in /tmp/docs/88250cec7b2b548e78bb5b003b625b1e78cf1c4a/Resources/getting-started/projects/rename-files.php on line 10

Delete Notebooks

Follow these steps to delete a notebook in a project:

  1. Open the project.
  2. In the left navigation menu, click the Explorer icon.
  3. In the Explorer panel, right-click the notebook you want to delete and then click Delete Permanently.
  4. Click Delete.

Learn Jupyter

The following table lists some helpful resources to learn Jupyter:

TypeNameProducer
Text Jupyter Tutorialtutorialspoint
Text Jupyter Notebook Tutorial: The Definitive GuideDataCamp
Text An Introduction to DataFrameMicrosoft Developer Blogs

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: