Back

Optimization Locally in LEAN/Visual Studio

I see that some people have accomplished developing optimization locally in LEAN but from the posts many people struggle debugging it and there is no clear walkthrough on how to do it.  In addition, most that have done this before have done it in C# and I'd like to have an example for python.  I'm going to attempt to work through this and then post a clear walkthrough for others to follow.  Since I have no formal coding experience I want the walkthrough to be understandable to anyone.

Background: I understand there are limitations with overfitting but I've got an algorithm that I would like to optimize several different parameters which would take 1000s of backtests to complete.  I definately hate doing this one by one.

Goal Example: Ability to backtest locally with equity data 200 times for algorithm parameter X using 0.5 unit increments from X=1 to X=100 and have some ability to quickly tabulate the results to determine which result was the best in terms of number of trades, drawdown, net profit

Problems to solve:

1. How to use equity data when backtesting locally.  From my understanding, due to vendor restrictions we cannot download the equity data locally to use.  However with the quanconnect plug in I think there is a way to use the cloud equity data when backtesting locally.  Eitherway, I need access to data for backtesting.  Doesnt need to be same day but pretty recent would be nice.

2. How to import my algo from the cloud to LEAN locally.  I have LEAN and visual studio on my laptop and I've downloaded other peoples algos like the "Genetic optimization" algo.  I have also figured out how to access my backtests locally but I dont know how to import a working algo saved on the website directly into LEAN locally.  IS that possible?

3.  How to set up parameters to optomize.

 

 

So far I have downloaded visual studio and have logged in to quantconnect through visual studio by following the directions in the link below:

https://www.quantconnect.com/tutorials/open-source/backtesting-from-visual-studio

Looks like desktop charting in LEAN is down right now.  It says its not supported anymore and Will be addressed in 2019

https://www.quantconnect.com/tutorials/open-source/desktop-charting-with-leanIf anyone has any suggestions for the 3 problems to solve above or any other comments suggestions or walkthroughs that might help with this project I would welcome them! Thanks everyone
Update Backtest







0

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.


Hi,

1. You cannot get Equity data locally, correct. Any backtests using Equity data will have to be run in the Terminal. The VS plug-in can only help you in starting those backtests, but it cannot somehow transfer the data back to your local machine.

2. Unsure if this is possible, save for a manual copy-paste of each file. Even if it was possible, I'm not sure how this would help you achieve your stated goal, though?

3. Depends what you want to achieve and how involved you want it to be. One creative solution could be to generate a list of all your parameter combinations and then have the backtest pick one in sequence each time you ran a backtest. You'd have to keep track of which iteration you were on, though.

 

If you'd like a solution that works for data that you can host locally (CFD, Forex, etc.), then feel free to check out Lean-Batch-Launcher or LeanOptimization. The former is a project I open-sourced recently that solves your problems and also lets your run Lean in parallel, saving a lot on execution time. It's best used for when you want to explore all parameter combinations. The LeanOptimization library is better for when you want to run genetic algorithms to optimise and find the best parameter combinations.

I should also note there's work being done to allow for optimisation in the Terminal, please see this link.

0

Yeah the reason I was trying to do this was because there have been posts about optimization in the Terminal since like 2016.  Figured we could figure it out locally and then there would be a method to do this now instead of waiting for if/when it gets completed online.

I've looked at leanoptimizer a lot.  Thats exactly when I was hoping to do with equities and in python and then write up a walkthrough that anyone can understand.  Couple issues I have with the leanoptimizer is that its in C# so i would have to convert my algo over from python.  The other issue is I dont fully understand it cause there isnt a simple walk through and I'm pretty much a total idiot at this stuff lol  

The lean-batch-launcher is pretty much exactly what I waant to do but in python and for equities.  Might not be possible if I cant access the data.  I think you can run the tests locally and use the pricing data on the cloud though.  May be wrong about that

0

Update Backtest





0

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.


Loading...

This discussion is closed

 
";