LEAN Desktop Development Best Practices for Repo Structure?

Hello, I've got LEAN running on my local machine and am exploring the features. However, I'm wondering about the best practices for management of the LEAN repo. Both config.json and algorithm files are located within the LEAN repo. I would like to separate the LEAN engine from any custom configurations and algorithms so that I can keep the LEAN repo clean and free of my own changes. This should make merging changes from LEAN development painless.

It looks likes I can edit the config.json to point to algorithms in different locations, so that should allow me to keep my algos in a separate repo. However, I still have in issue with the config file. Right now I'm just keeping different configs in different branches. But I think that I'd like the configs in the same repo as the algos. However, I'm open to other solutions.

How do YOU structure your repos to separate the LEAN engine from your own algos and custom configs? Is there a recommended best practice?

Update Backtest

Hi GregasMaximus,

I'm doing the same thing. I have a seperate Visual Studio solution/repo that holds my algorithms. I branched off the master branch of Lean to make a few small changes mainly to config files. It works okay for now but if i start making more changes to my branch it might be more of a problem merging later.



This is a good question and was discussed briefly over Slack a while ago. Let me suggest two different set-ups, one where the only changed file is config.json and one where the LEAN repo is left completely untouched but where you'll need to write your own launcher (I'll mention this purely for inspiration).

Setup #1 (only requires edits to config.json)

  1. Create a git repo and import the LEAN repo as a git submodule in a subdirectory of choice - I store it in ./Lib/Lean/.
  2. Create a master solution, AlgorithmSolution, in the root of your repo.
  3. Create a project within this solution, Algorithm. This is where you store all your work - your alphas, risk management modules, etc. along with the main class extending QCAlgorithmFramework.
  4. Follow this guide at MSDN to import the entire QuantConnect solution (not just the individual projects) into your AlgorithmSolution. The advantage with this approach is that you shouldn't need to edit any of the sln's or csproj's with new folder paths etc., which would normally happen if you were to just import the individual csproj's. Also, now that you've imported the actual solution, the addition of any new projects (rare, but can happen) will, after updating your repo, be reflected in your solution automatically without any extra work.
  5. Ensure your Algorithm project references the necessary QC libraries.
  6. Voila! The only file you'll now need to edit is config.json. Using a git tool of choice, check the git status of the LEAN submodule - you should see that no files are edited apart from the config.
  7. If you want to be efficient in your edits to config.json, put all your changes at the end of the file - this way, you can quickly and easily pull in a new version from remote and just re-apply your changes again, should you need to.
Setup #2 (leaves LEAN completely untouched)
  1. Follow steps 1-5 above.
  2. Create an Algorithm.Launcher project in your solution.
  3. Taking inspiration from QuantConnect.Lean.Launcher.Program, write your own launcher, and have it reference a different location for your config file.
  4. Set your startup project in Visual Studio to be Algorithm.Launcher.
  5. The advantage of this method is that you now have complete control over how your algorithm is launched, meaning you can implement things like parallel backtesting, optimisation, etc. The downside is, of course, that you're re-writing code and that you have to keep an eye on the remote version of Launcher to see if anything meaningful changes between revisions.
 Hope this helps you! I hope I haven't forgotten anything. Let me know if you have any questions. 

Thanks for the detailed info! That is super helpful.


Update Backtest


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This discussion is closed