Skip to content
Lean Algorithmic Trading Engine by QuantConnect (C#, Python, F#)
C# HTML Python Jupyter Notebook Visual Basic Batchfile
Branch: master
Clone or download
Latest commit de19f7e Oct 15, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Contributing using the correct branch naming convention Feb 27, 2019
Algorithm.CSharp Merge pull request #3710 from gsalaz98/feature-cboe-vix-basedata Oct 15, 2019
Algorithm.FSharp Add missing reference in Algorithm.FSharp Sep 24, 2019
Algorithm.Framework Improves ETF Basket Universe Selection Models Oct 3, 2019
Algorithm.Java Specify <LangVersion> of 6 in all csproj files Aug 7, 2017
Algorithm.Python Merge pull request #3710 from gsalaz98/feature-cboe-vix-basedata Oct 15, 2019
Algorithm.VisualBasic Update Json.Net to 9.0.1 Mar 13, 2017
Algorithm Improves ETF Basket Universe Selection Models Oct 3, 2019
AlgorithmFactory PythonNet bump Sep 23, 2019
Api Update Api to respect CA1304 and CA1305 Sep 12, 2019
Brokerages Merge branch 'master' into bitfinex-brokerage-get-history-improve-the… Sep 30, 2019
Common Merge pull request #3710 from gsalaz98/feature-cboe-vix-basedata Oct 15, 2019
Compression Update Compression/Jupyter/Launcher/Queues/UserInterface to respect C… Sep 12, 2019
Configuration Adding Tiingo new data converter Oct 1, 2019
Data Update SG30SGD Exchange time zone Oct 8, 2019
Documentation documentation image update Oct 21, 2017
Engine Merge pull request #3677 from QuantConnect/bug-3676-backtestingfuture… Oct 7, 2019
Indicators Implements Backward Compatibility for Python Custom Indicator Oct 4, 2019
Jupyter Merge pull request #3704 from QuantConnect/research-improvements Oct 10, 2019
Launcher Update Compression/Jupyter/Launcher/Queues/UserInterface to respect C… Sep 12, 2019
Logging Update Logging to respect CA1304 and CA1305 Sep 12, 2019
Messaging Add StringExtensions and Parse utilizing CultureInfo.InvariantCulture Aug 16, 2019
PythonToolbox Refactor and fix bugs in function for processing dictionary to image … Aug 13, 2019
Queues Update Compression/Jupyter/Launcher/Queues/UserInterface to respect C… Sep 12, 2019
Tests Merge pull request #3703 from AlexCatarino/feature-3576-adds-python-p… Oct 11, 2019
ToolBox Update CoinApiDataQueueHandler to use CoinApi's NuGet package (#3645) Oct 11, 2019
VisualStudioPlugin Add StringExtensions and Parse utilizing CultureInfo.InvariantCulture Aug 16, 2019
.dockerignore Updated dockerfiles to include headless linux support for IB Nov 13, 2016
.gitattributes Update .gitattributes for sh to use lf eol Apr 15, 2015
.gitignore Implement API download for QCALgorithm (#3215) May 21, 2019
.travis.yml Update Travis mono version Sep 30, 2019 Contributing using the correct branch naming convention Feb 27, 2019
Dockerfile Commenting out steps 1. Oct 9, 2019
DockerfileJupyter Update DockerfileJupyter Sep 6, 2019
DockerfileLeanFoundation Uses Self-Hosted Packages Oct 10, 2019
LICENSE Update LICENSE Jul 10, 2015
QuantConnect.Lean.VS15.sln Removes QuantConnect.Views project Aug 14, 2019
QuantConnect.Lean.sln Removes QuantConnect.Views project Aug 14, 2019
QuantConnect.Lean.sln.DotSettings Merge pull request #3379 from AlexCatarino/pr3368 Aug 14, 2019
QuantConnect.ruleset Enforce CA1304 and CA1305 as build errors Sep 12, 2019
lean.ico Rework GetResultHandler to use type loader; first desktop UX implemen… Jun 7, 2015 Update Oct 1, 2019

alt tag

Build Status     LEAN Forum     Slack Chat

Lean Home - | Documentation | Download Zip


Lean Engine is an open-source algorithmic trading engine built for easy strategy research, backtesting and live trading. We integrate with common data providers and brokerages so you can quickly deploy algorithmic trading strategies.

The core of the LEAN Engine is written in C#; but it operates seamlessly on Linux, Mac and Windows operating systems. It supports algorithms written in Python 3.6, C# or F#. Lean drives the web based algorithmic trading platform QuantConnect.

QuantConnect is Hiring!

Join the team and solve some of the most difficult challenges in quantitative finance. If you are passionate about algorithmic trading we'd like to hear from you. The below roles are open in our Seattle, WA office. When applying, make sure to mention you came through GitHub:

  • Developer Advocate: How can we educate 80k+ quants at scale? Strategize and create video content, documentation, interactive tutorials, and other content to empower the community.

  • Quantitative Developer: Work daily with a brilliant community of developers, scientists, mathematicians, and traders as you enable them to bring their strategies to life.

  • Quantitative Development Intern: If you are a recent or current graduate with a knack for quantitative finance, consider applying for an internship!

System Overview

alt tag

The Engine is broken into many modular pieces which can be extended without touching other files. The modules are configured in config.json as set "environments". Through these environments you can control LEAN to operate in the mode required.

The most important plugins are:

  • Result Processing (IResultHandler)

    Handle all messages from the algorithmic trading engine. Decide what should be sent, and where the messages should go. The result processing system can send messages to a local GUI, or the web interface.

  • Datafeed Sourcing (IDataFeed)

    Connect and download data required for the algorithmic trading engine. For backtesting this sources files from the disk, for live trading it connects to a stream and generates the data objects.

  • Transaction Processing (ITransactionHandler)

    Process new order requests; either using the fill models provided by the algorithm, or with an actual brokerage. Send the processed orders back to the algorithm's portfolio to be filled.

  • Realtime Event Management (IRealtimeHandler)

    Generate real time events - such as end of day events. Trigger callbacks to real time event handlers. For backtesting this is mocked-up an works on simulated time.

  • Algorithm State Setup (ISetupHandler)

    Configure the algorithm cash, portfolio and data requested. Initialize all state parameters required.

For more information on the system design and contributing please see the Lean Website Documentation.

Installation Instructions

Download the zip file with the latest master and unzip it to your favorite location.

Alternatively, install Git and clone the repo:

git clone
cd Lean


Visual Studio will automatically start to restore the Nuget packages. If not, in the menu bar, click Project > Restore NuGet Packages.

  • In the menu bar, click Run > Start Debugging.

Alternatively, run the compiled exe file. First, in the menu bar, click Build > Build All, then:

cd Lean/Launcher/bin/Debug
mono QuantConnect.Lean.Launcher.exe

Linux (Debian, Ubuntu)

sudo apt-get update && sudo rm -rf /var/lib/apt/lists/*
sudo apt-key adv --keyserver hkp:// --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb stable-xenial/snapshots/ main" > /etc/apt/sources.list.d/mono-xamarin.list && \
    apt-get update && apt-get install -y binutils mono-complete ca-certificates-mono mono-vbnc nuget referenceassemblies-pcl && \
apt-get install -y fsharp && rm -rf /var/lib/apt/lists/* /tmp/*

If you get this error on the last command:

Unable to locate package referenceassemblies-pcl,

run the following command (it works on current version of Ubuntu - 17.10):

echo "deb xenial main" | sudo tee /etc/apt/sources.list.d/mono-official.list
sudo apt-get update
sudo apt-get install -y binutils mono-complete ca-certificates-mono referenceassemblies-pcl fsharp
  • Install Nuget
sudo apt-get update && sudo apt-get install -y nuget
  • Restore NuGet packages then compile:
nuget restore QuantConnect.Lean.sln
msbuild QuantConnect.Lean.sln

If you get: "Error initializing task Fsc: Not registered task Fsc." -> sudo apt-get upgrade mono-complete

If you get: "XX not found" -> Make sure Nuget ran successfully, and re-run if neccessary.

If you get other errors that lead to the failure of your building, please refer to the commands in "DockerfileLeanFoundation" file for help.

  • Run the compiled exe file:
cd Lean/Launcher/bin/Debug
mono ./QuantConnect.Lean.Launcher.exe
  • Interactive Brokers set up details

Make sure you fix the ib-tws-dir and ib-controller-dir fields in the config.json file with the actual paths to the TWS and the IBController folders respectively.

If after all you still receive connection refuse error, try changing the ib-port field in the config.json file from 4002 to 4001 to match the settings in your IBGateway/TWS.


  • Install Visual Studio
  • Open QuantConnect.Lean.sln in Visual Studio
  • Build the solution by clicking Build Menu -> Build Solution (this should trigger the Nuget package restore)
  • Press F5 to run

Nuget packages not being restored is the most common build issue. By default Visual Studio includes NuGet, if your installation of Visual Studio (or your IDE) cannot find DLL references, install Nuget, run nuget on the solution and re-build the Solution again.

Python Support

A full explanation of the Python installation process can be found in the Algorithm.Python project.

R Support

  • Install R-base if you need to call R in your algorithm. For Linux users:
sudo apt-get update && apt-get install -y r-base && apt-get install -y pandoc && apt-get install -y libcurl4-openssl-dev

For Windows and macOs users: Please visit the official R website to download R.

QuantConnect Visual Studio Plugin

For more information please see the QuantConnect Visual Studio Plugin Documentation

Issues and Feature Requests

Please submit bugs and feature requests as an issue to the Lean Repository. Before submitting an issue please read others to ensure it is not a duplicate.

Mailing List

The mailing list for the project can be found on LEAN Forum. Please use this to request assistance with your installations and setup questions.

Contributors and Pull Requests

Contributions are warmly very welcomed but we ask you read the existing code to see how it is formatted, commented and ensure contributions match the existing style. All code submissions must include accompanying tests. Please see the contributor guide lines.

All accepted pull requests will get a 2mo free Prime subscription on QuantConnect. Once your pull-request has been merged write to us at with a link to your PR to claim your free live trading. QC <3 Open Source.


The open sourcing of QuantConnect would not have been possible without the support of the Pioneers. The Pioneers formed the core 100 early adopters of QuantConnect who subscribed and allowed us to launch the project into open source.

Ryan H, Pravin B, Jimmie B, Nick C, Sam C, Mattias S, Michael H, Mark M, Madhan, Paul R, Nik M, Scott Y,, Tadas T, Matt B, Binumon P, Zyron, Mike O, TC, Luigi, Lester Z, Andreas H, Eugene K, Hugo P, Robert N, Christofer O, Ramesh L, Nicholas S, Jonathan E, Marc R, Raghav N, Marcus, Hakan D, Sergey M, Peter McE, Jim M,, Richard E, Dominik, John L, H. Orlandella, Stephen L, Risto K, E.Subasi, Peter W, Hui Z, Ross F, Archibald112,, Jae S, Eric S, Marco D, Jerome B, James B. Crocker, David Lypka, Edward T, Charlie Guse, Thomas D, Jordan I, Mark S, Bengt K, Marc D, Al C, Jan W, Ero C, Eranmn, Mitchell S, Helmuth V, Michael M, Jeremy P, PVS78, Ross D, Sergey K, John Grover, Fahiz Y, George L.Z., Craig E, Sean S, Brad G, Dennis H, Camila C, Egor U, David T, Cameron W, Napoleon Hernandez, Keeshen A, Daniel E, Daniel H, M.Patterson, Asen K, Virgil J, Balazs Trader, Stan L, Con L, Will D, Scott K, Barry K, Pawel D, S Ray, Richard C, Peter L, Thomas L., Wang H, Oliver Lee, Christian L.

You can’t perform that action at this time.