Research

The Research environment is a Jupyter notebook-based environment where you can explore and analyze alpha factors, backtests, and all data available on Quantopian.

We recommend that you familiarize yourself with Jupyter notebooks in order to efficiently use the Research environment. The basics will be outlined below; for a more in-depth exploration of Jupyter notebook cell types, keyboard shortcuts, and more, see the Introduction to Research lecture.

Running Code

Kernels

After you open a notebook, the underlying kernel will start. This essentially begins a new Python session. The kernel "remembers" all variables defined during the session, but cannot access variables from other kernels or previous sessions.

Even if you close the notebook tab, restart your browser, or log out of your account, the kernel will continue to run. For example, if you set x = 5 in your notebook, close your browser, then re-open your browser and open the notebook, running x will still return 5.

Each Quantopian account has a set limited amount of Research memory (RAM). If you hit the memory limit, you won't be able to store any new variable values or information in your research notebooks. Any notebook that is running takes up some Research memory (the specific amount depends on what variables you've defined and compuations you've run in your notebook). As such, we recommend shutting down research notebooks that you are no longer actively using.

To shut down a research notebook, navigate to the notebooks page. The running notebooks will be shown in green; non-running notebooks are shown in gray. Check the boxes of the running notebooks you wish to stop, then click the "stop" button in the upper left corner. Note that shutting down a notebook has no effect on your code, but will erase all stored variables. To start the kernel again, simply open the notebook.

Note

When you open up a notebook, there is a memory meter in the upper right hand corner of the notebook interface that shows you the % of available memory you are using across all notebooks. Use this to keep track of when you might need to shutdown notebooks to free up memory.

Cells

Once your kernel starts, you will be able to run code in your notebook. Jupyter notebooks are cell-based, which means that code is run in the order that you run the cells (which doesn't necessarily have to be top-to-bottom). Within a cell, code is run from top-to-bottom.

To run a cell, click the "Run Cells" menu option or press SHIFT + RETURN after clicking into a cell.

Keyboard Shortcuts

The Jupyter Notebook has two different keyboard input modes. Edit mode allows you to type code or text into a cell and is indicated by a green cell border. Command mode binds the keyboard to notebook level commands and is indicated by a grey cell border with a blue left margin. You can enter Edit mode by clicking into a cell (or pressing RETURN) and you can enter Command mode by clicking outside a cell (or pressing ESC).

Jupyter provides you with a number of shortcuts that make it easy to navigate and work on your notebook. To see the list of all commands supported both Edit mode and Command mode, enter Command mode (by pressing ESC when in a notebook), and then press H (for "help"). Of the many helpful commands you can use to speed up your workflow in a notebook, here are some of the most popular ones:

Edit Mode

  • SHIFT + TAB (press twice) - When your cursor is at the end of a function or class reference, this command will pull up an interactive version of the docstring for the function/class.
  • CMD/CTRL + [ - Indent line or highlighted lines of code.
  • CMD/CTRL + ] - Dedent line or highlighted lines of code.
  • CMD/CTRL + A - Select all.
  • CMD/CTRL + Z - Undo.
  • CMD/CTRL + SHIFT + Z - Redo.
  • CMD/CTRL + / - Toggle comment/uncomment line or highlighted lines of code.

Command Mode

  • CMD/CTRL + A - Add cell above.
  • CMD/CTRL + B - Add cell below.
  • D, D (double tap D) - Delete selected cell(s).
  • CMD/CTRL + M - Change cell to markdown (useful for writing prose instead of code).
  • CMD/CTRL + Y - Change cell to code.

Importing Modules

For security reasons, only specific modules are whitelisted for import. In Research, you can import anything on the Algorithm IDE Whitelist. In addition, there are some extra modules and functions that are only available in Research (not the IDE), and those are listed in the Research Whitelist. These are primarily visualization libraries.

Managing Notebooks

The following actions are possible for notebook files in your Research environment:

Saving: Notebooks are saved automatically every two minutes. To manually save a notebook, click the "Notebook" menu and select "Save and Checkpoint".

Deleting: To delete a notebook, select the notebook on the main "Notebooks" page, then click the orange "Trash" icon. If the notebook is running, you will need to shut it down before deleting it.

Reorganizing: You can move notebooks into directories by dragging and dropping them. You can move a notebook up a level in the directory structure by dragging it to the .. directory. Note that running notebooks cannot be moved into another directory. You will need to shutdown a running notebook if you want to move it.

Sharing: You can share notebooks with other Quantopian members through posts in the community. To share a notebook in a community forum post, start writing a forum post, then click "Attach" in the upper-right corner of the text field and select the desired notebook.

Uploading/Downloading: You can upload Jupyter notebooks (.ipynb files) to Research from your local machine. To do this, click the "Upload" button in the upper right corner, then select the .ipynb file you'd like to upload. You can also download Research notebooks to your local machine. To do this, click the "Notebook" menu in the top right corner. Then click "Download as" and select the appropriate option. If you want to download the notebook to send to someone else so they can upload it and use it on Quantopian, you should download it as a .ipynb file. If you instead want to send it to someone who wants to see the output, but doesn't plan to run the notebook themselves, downloading as .html is a good option.

Note

Though you can download Research notebooks locally, your code will not run locally if it uses Quantopian-specific functions or data. The primary reason to download a Research notebook is to send it to someone else to upload and use on Quantopian.

Visualizing Data

Data visualization can be extremely useful in your research. Many of the tools available on Quantopian like Alphalens and Pyfolio rely on plots to communicate results.

Beyond the plots generated by Quantopian tools, you can also generate your own plots using external Python libraries.

To learn more about data visualization in Research, check out the documentation and examples for common visualization libraries. The following libraries are whitelisted and available to use in Research.

For interactive plotting, see the Qgrid introduction or Qgrid documentation. Qgrid interacts with these plotting libraries so that you can easily update plots as you manipulate your data.