https://github.com/jameschch/LeanParameterOptimization
Parameter optimization for LEAN
This toolset allows you to execute multiple parallel backtests using a local Lean clone. It is possible to configure several different optimization methods to fit your trading algorithm to an array of different success measures.
You must edit the config file optimization.json to define parameters and other settings. The gene values are fed into the Lean config and can be accessed in an algorithm using the QuantConnect.Configuration.Config methods.
An example algorithm is provided here: ParameterizedAlgorithm
- Clone local Lean.
- Clone the Optimizer so that it shares the same parent folder as the Lean clone.
- Edit the config file and enter the location of your trading algorithm dll in "algorithmLocation".
- Now enter the class name of your algorithm in "algorithmTypeName".
- Enter the location of your trade and quote bar data in the "dataFolder" setting.
- Configure the maxThreads to define the number of parallel backtests.
Full documentation is provided in comments: OptimizerConfiguration
The most important options:
The default OptimizerFitness is a simple Sharpe Ratio tournament. There is also CompoundingAnnualReturnFitness to maximize raw returns. It is possible to optimize any Lean statistic using ConfiguredFitness.
Specifying the SharpeMaximizer fitness allows access to all of the optimization methods provided by the SharpLearning library. These include Random Search. Grid Search, Particle Swarm, Smac and several others.
The simple SharpeMaximizer has been extended in NFoldCrossSharpeMaximizer so that the success score is measured over N-fold periods. This will prevent overfitting to a single in-sample period but is not guaranteed to eliminate overfitting entirely. There are several other fitness measures that operate over multiple periods.