Lean Algorithmic Trading Engine by QuantConnect (C#, Python, F#)
Switch branches/tags
algo-timeout-stacktrace alpaca-brokerage alpha-heartbeat alpha-value-monthly bitfinex bug-337-add-support-for-python-project-directories bug-2187-remove-framework-pop-avg-score-warmup-period bug-2189-parralelize-fine-fundamental-reading bug-2288-pythonnet-memory-leak bug-2357-fix-insight-close-time bug-2381-daily-benchmark-for-backtesting bug-2381-setbenchmark-fix bug-2504-ib-always-restore-data-subscriptions bug-2513-performcashsync-once bug-2532-apply-splits-in-live-mode bug-2541-live-mode-always-apply-splits-never-apply-dividends bug-2569-apply-dividends-in-live-paper bug-2569-double-dividend-application bug-2611-live-trading-sync-algorithm-status-update bugfix-insight-close-time crypto-symbol-length debugging-api-logging desktop-mk-ii docker-file-lean-foundation-updates feature-452-net-core feature-1040-object-store feature-1093-vwap-order-type feature-1418-buying-power-order-fee-contexts feature-1418-fee-model-units feature-2003-kraken-exchange feature-2047-split-dividend-api feature-2060-multi-leg-currency-conversion feature-2068-refactor-regression-test-suite feature-2271-IRegressionAlgorithmDefinition-CanRunLocally feature-2378-fix-stream-reader-disposal feature-2378-generator-factors feature-2378-live-factor-files feature-2378-minor-split-dividend-fixes feature-2378-split-dividend-improvements feature-2581-multiple-risk-models feature-timestamped-packets feature/1418-fee-model-context feature/2606-custom-brokerage-message-handler features-1998-2219-portfolio-implementation-v2 fix-python-algorithm-loading fix-vix-futures-scale-factor fsdf-thread-count-logging ib-restart-handler-fix ibrokeragemodel-isshortsellingallowed live-test-add-orderfee-to-orderevent live-test-move-addsubscription-removesubscription log-splits-dividends master multiple-brokerages quandl-live-extra-logging refactor-1418-buying-power-model-context refactor-2491-livetradingdatafeed-will-use-subscriptionsynchronizer refactor-2567-fill-fee-model-invocation refactor-remove-job-packet release-engine-test smarter-live-chart-subscriptions symbol-tostring-no-subscription test-insight-scoring tick_not_decimal track-all-security-subscriptions trade-crypto-history-requests tweak-2530-log-split-dividend-prices tweak-configure-await-extension tweak-improve-map-file-read-time tweak-make-InsightFromSerializedInsight-public tweak-minor-changes-splits-dividends
Nothing to show
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Fixes typo in pull request template Jul 3, 2018
Algorithm.CSharp Refactor IFeeModel Dec 6, 2018
Algorithm.FSharp Rebase with pythonnet/master and fix datetime UTC bug Jul 16, 2018
Algorithm.Framework Merge pull request #2657 from QuantConnect/bug-2656-macd-alpha-model-… Nov 9, 2018
Algorithm.Java Specify <LangVersion> of 6 in all csproj files Aug 7, 2017
Algorithm.Python Refactor IFeeModel Dec 6, 2018
Algorithm.VisualBasic Update Json.Net to 9.0.1 Mar 13, 2017
Algorithm Obsoleting Securities configurations properties Dec 5, 2018
AlgorithmFactory Load algorithm faster Oct 18, 2018
Api Add missing null check in Api.ReadPrices Aug 22, 2018
Brokerages Refactor IFeeModel Dec 6, 2018
Common Merge pull request #2720 from Martin-Molinero/refactor-2717-ifeelmodels Dec 6, 2018
Compression Keep directory structure in Compression.UnzipToFolder Jun 19, 2018
Configuration corrected CLI prompt Jul 24, 2018
Data Include observance of mourning day for President George H. W. Bush Dec 4, 2018
Documentation documentation image update Oct 21, 2017
Engine Obsoleting Securities configurations properties Dec 5, 2018
Indicators Fix XML documentation compiler warnings Nov 9, 2018
Jupyter Obsoleting Securities configurations properties Dec 5, 2018
Launcher configuration parameter adjust Oct 19, 2018
Logging Suppressing inlining on methods that call WhoCalledMe Jul 27, 2018
Messaging Improve process for updating regression statistics Jun 7, 2018
PythonToolbox Update README.rst Jul 20, 2018
Queues Adding a configuration for maximum data points per chart series. Limi… Aug 17, 2018
Tests Merge pull request #2720 from Martin-Molinero/refactor-2717-ifeelmodels Dec 6, 2018
ToolBox Convert from CRLF to LF for GDAXDownloader Oct 28, 2018
UserInterface Specify <LangVersion> of 6 in all csproj files Aug 7, 2017
VisualStudioPlugin Update readme.md Jul 12, 2018
.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 Creates QuantConnect ApiPython project Feb 9, 2018
.travis.yml Refactors BlackLittermanOptimizationPortfolioConstructionModel Aug 20, 2018
CONTRIBUTING.md Minor corrections Oct 26, 2018
Dockerfile Fix unzip command Sep 24, 2018
DockerfileJupyter Update download paths to cdn.quantconnect.com Aug 6, 2018
DockerfileLeanFoundation Update download paths to cdn.quantconnect.com Aug 6, 2018
LICENSE Update LICENSE Jul 10, 2015
QuantConnect.Lean.VS15.sln Add Algorithm.Framework to VS15.sln Apr 30, 2018
QuantConnect.Lean.sln Initial commit of LeanReportCreator Jun 6, 2018
QuantConnect.Lean.sln.DotSettings Fix duplicate application of diviends in live paper Oct 11, 2018
lean.ico Rework GetResultHandler to use type loader; first desktop UX implemen… Jun 7, 2015
readme.md Update to LEAN logo Jun 1, 2018
setup.py Adds more requirements checks and updates readme Aug 13, 2018


alt tag

Build Status     Google Group     Slack Chat

Lean Home - https://www.quantconnect.com/lean | 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.

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 lastest master and unzip it to your favorite location.

Alternatively, install Git and clone the repo:

git clone https://github.com/QuantConnect/Lean.git
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://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy/snapshots/ main" > sudo /etc/apt/sources.list.d/mono-xamarin.list

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 http://download.mono-project.com/repo/ubuntu 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
xbuild 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 Google Groups. 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 support@quantconnect.com 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, BinaryExecutor.com, 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, INTJCapital.com, Richard E, Dominik, John L, H. Orlandella, Stephen L, Risto K, E.Subasi, Peter W, Hui Z, Ross F, Archibald112, MooMooForex.com, 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.