I am just wondering if you're going to develope an strategy optimization functionality. From my point of view this is the missing piece in the system. Probably that also would mean to implement as well some sort of parametrization function.
Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
User requests strategy optimization and parameterization function for QuantConnect.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Strategy Optimization
Emilio Lopez | March 2015
I am just wondering if you're going to develope an strategy optimization functionality. From my point of view this is the missing piece in the system. Probably that also would mean to implement as well some sort of parametrization function.
QuantConnectâ„¢ 2025. All Rights Reserved
Jared Broad
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.
Alexandre Catarino
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
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.
Alexandre Catarino
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.
Felix Bertram
This sounds all awesome. Is there an update on the status?
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.
James Smith
I have a working genetic optimization system here:
https://github.com/jameschch/LeanOptimization/tree/geneticSharp
This is based on the old LeanOptimization project, but I have made it much more configureable, ported it to a different genetic framework and enabled parallel backtests. This is not an official release as it requires some minor and subtle changes to Lean that may not be compatible with the master branch. As you imagine, work is ongoing and this is not the officially approved Lean optimization solution, it's just a tool some might find useful.
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.
Ryan Witt
Great work, James. I've been playing with your LeanOptimization fork for a couple weeks now. A quick pointer for anyone else looking at toying with it: set a few conditions in your algo that Quit() early if things aren't looking like you want.
Quitting at a certain drawdown is a fairly obvious one. I am doing a fair amount of filtering of signals in the project I'm working on, which can lead to little-to-no trades being executed if the filter parameters aren't tuned properly, so I've added a scheduled check to ensure a minimum number have trades have been opened after a month or so of testing.
This can add quite a speed-up, especially early on in the optimization process before it begins honing in. Probably not a bad idea to add those even for non-optimizing backtests, but it never really crossed my mind until I was looking at running 10k tests in one go. I've seen up to a 50% reduction in the time required to get past the first few generations when I hadn't really figured out sane ranges for parameters yet.
One other thing I found helpful was tweaking the output to optimizer.txt so that it spits out things already CSV formatted -- it makes it a bit less tedious to dump results into R for further examination.
Unfortunately, the results I'm getting tend to be fairly brittle -- I think overfitting is a real concern on two fronts. First, you're only optimizing against a single backtest period. Being able to easily run the results of the top n results against an out-of-sample window would be nice. I think there may be a way to prepopulate genes which would take care of that, but I haven't looked into it much. The second thing I think could be helpful would be some sort of fuzzing on parameters, so you could determine if you've found something that is in a solid range or if you just happened to stumble on the perfect combination (I've had things that went from Sharpe around 2 to -1 when I changed a single int parameter by 1).
I'll think some more on all that, and send a PR your way if I come up with anything.
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.
James Smith
Really pleased you took the time to get this going. This is fairly rough code as I hadn't given much thought to general consumption.
I'd agree having the algorithm quit early speeds up the discovery especially where I'm using wide param ranges to discover a new alpha by brute force. Improperly tuned params is a general problem though, so am looking for different solutions.
I think over fitting is endemic to genetic approaches. The method I have been using to counteract this is to run optimisations separately on multiple periods. I then test these candidates against out of sample data and select the best. Another method is to run multiple optimisations but on the second run changing the in-sample period and predefining the gene with the results from the previous run. You can preloaded the first generation with fixed values by setting the "actual" for a gene in the file "optimisation.json".
It would also be possible to create a chromosome that comprises of two gene sets that target two different sample periods. The fitness is then a function of the Sharpe of these two periods, however, the average of a high with low Sharpe hides the overfit of the high. I have also thought about random selection of in-sample period but not progressed this.
I've tried a few different selections, crossovers and mutations from the genetic sharp library. The build includes the options I've found most suitable but am considering making these configurable.
Go ahead and suggest anything else that comes to mind.
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.
James Smith
I've been thinking further about your remarks on fuzzing, It would be possible to create an optimzation.json with a small value range and then run the optimizer for a few generations. If you see a large deviation in the sharpe, you will know the main proposition is flawed.
To automate this kind of thing we're getting into the domain of multiple optimization batches and a recursive/introspective execution model.
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.
Ryan Witt
That is pretty much what I've been doing. I'll take the results, select a handful of the top ones that are sufficiently different from one another, and rerun each of them with a small range. When I find one that continues to be successful, I change the backtesting period and repeat. That seems to do a pretty good job of weeding out good and bad ideas (and implementations -- I have found a few bugs in my code that I don't know I would have spotted without results from thousands of runs readily at hand). I've also had a few cases where all but one parameter is pretty robust to changes, which has helped narrow my focus on areas that need improvement -- it was worth the cost of admission just for those things alone.
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.
James Smith
Yes, running 24000 backtests automatically is occasionally useful.
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.
James Smith
I've now settled on a stable build of the LEAN genetic optimizer and have added all the features that I had planned:
https://github.com/jameschch/LeanOptimization
Please feel free to provide any feedback if you get it running.
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.
Carl S
Any update on when this will be added?
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.
Petter Hansson
Currently looking forward to this as well, because it's going to help me do what I'm already doing more effectively.
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.
James Smith
If you're able to get LEAN up and runnning on a local desktop or server(s), you have the option of using the LeanOptimization Genetic Optimizer that's available here:
https://github.com/jameschch/LeanOptimization
In order to run parallel backtests, a small change is required to the QC master build. I have made available a compatible branch of LEAN here:
https://github.com/jameschch/Lean/tree/optimizer
The initial setup and configuration should not be very time consuming, but I'm in the process of simplifying things.
Anyone interested in algorithm optimization would be welcome to make suggestions. I'm currently considering several new feature areas:
-different ways to calculate algorithm fitness scores (apart from Sharpe Ratio)
-improving processing times with machine learning classifiers
-zero code configuration installer
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.
Kc chu
I am new to Lean and C#, can anyone show me how to use the lean optimization. I have downloaded leanoptimization but I dont know how to merge with the lean source code to compile the solution.
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.
James Smith
Hi KC chu, nice that you've taken interest in this. I think the first step is going to be getting familiar with Lean https://github.com/QuantConnect/Lean
The main developers of the project will respond here and on github and they're all very helpful. You might ease yourself in by developing some algorithms through the QC console before moving onto a local environment.
In terms of parameter optimization, I've recently been working on this and have provided a means to automate parallel execution of backtests with a genetic optimizer. This is available here:
https://github.com/jameschch/LeanOptimization
If you wish to enable parallel logging, you will need to modify your lean build as per this commit:
https://github.com/jameschch/Lean/commit/0115dabd16b0d6e88794b20f7415d76702349c6
If you're familiar with running algorithms in Lean, the optimizer should be fairly familiar. I would suggest you run the example algorithm first and then change the configuration to suit your needs:
https://github.com/jameschch/LeanOptimization/blob/master/Optimization/optimization.json
The supported config settings are documented here:
https://github.com/jameschch/LeanOptimization/blob/master/Optimization/OptimizerConfiguration.cs
This project is still being actively developed, so if you have a feature idea or encounter an issue, please submit your feedback through github. I think that currently, there is a fairly steep curve for a new user to get started with the optimizer, which is something I hope to address sometime soon.
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.
Larry Smith
James Smith - i am also interested in contributing, i am bit lost as to how this solution may be used as a robo-trader and/or exchange.
Is there documentation as to data flow and/or sequence diagrams including primary system interfaces?
I found one PDF..
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.
Kc chu
I have tried the examples in the leanoptimization but unsuccessful. I get OutofMemeoryException at above 7th generation and no results are output.
The followings are recorded at the optimizer.txt
2017-03-30 23:26:00Z Algorithm: ParameterizedAlgorithm, Generation: 1, Fitness: 0, : -10
2017-03-30 23:26:09Z Algorithm: ParameterizedAlgorithm, Generation: 2, Fitness: 0, : -10
2017-03-30 23:26:21Z Algorithm: ParameterizedAlgorithm, Generation: 3, Fitness: 0, : -10
2017-03-30 23:26:35Z Algorithm: ParameterizedAlgorithm, Generation: 4, Fitness: 0, : -10
2017-03-30 23:26:51Z Algorithm: ParameterizedAlgorithm, Generation: 5, Fitness: 0, : -10
2017-03-30 23:27:04Z Algorithm: ParameterizedAlgorithm, Generation: 6, Fitness: 0, : -10
2017-03-30 23:27:21Z Algorithm: ParameterizedAlgorithm, Generation: 7, Fitness: 0, : -10
Can james provide a more precise step by step guide/screenshot showing how to config and compile the example?
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.
James Smith
@Kc chu
Its good you were able to execute: this means the referenced assemblies were built and found. It may be you have not configured the dataFolder or configPath in "optimization.json". These should be paths from the optimization executable to the relevant locations in your local lean clone. The configPath refers to the "config.json" which should be in the launcher bin folder. The dataFolder is the folder named data that holds the market hours, symbol properties and historical price data. This will be a relative path in the lean clone, but needs to be changed so that the relative path is from the optimization.exe bin folder.
If you get stuck you can run in debug mode and step from the optimizer into the lean classes and on into the algorithm. A simplified initial setup process and docs are one of the areas being worked on currently.
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.
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!