Optimization Locally in LEAN/Visual Studio

Back

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. 

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

David could you share you achievements and lessons. I really want to start with equities too but there are so many obstacles doing it locally. 

0

We're working on this now Valentas; we never had a sustainable business model to make it happen but with the organization and cloud redesign its in full swing! ETA November. 

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.


Jared Broad Can you confirm this is the ETA for parameter search or optimization? Will it run locally or on the cloud? Hoping it's local.

To be honest I've given this a good go using local Lean, but have been unsuccessful. 

I'm at the point of moving away from QC and building my own backtesting and parameter search algorithm. I have most of the building blocks already from prior work but the architecture is not as clean as QC. The issue will be i) whenever I need new data, need to run a download script from IB. ii) need to code connectivity to another broker since IB leverage for forex is too low.

 

 

 

0

Hi Dat En,

Yes, the parameter optimization will run locally.

(1) LEAN is under active development.

(2) QC tutoring is now fulfilled by expert community members. Join our Slack channel to find a tutor.

Moving away from QC to build a proprietary search algorithm would require a substantial amount of work. Consider waiting for our integrated solution.

Best,
Derek Melchin

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.


Derek Melchin thanks. Nov is just around the corner and I'll be waiting with bated breath!

I notice this feature has been discussed going back several years so will be good to finally have it....

0

Hi Dat En,

We don't have an official release date, but this feature is under active development. Track the progress here.

Best,
Derek Melchin

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.


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...

To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!