Bad optimization results or "ValueError: Too many errors! less than half of the expected population size could be generated."

The first thing to understand is that the optimization uses a fitness score to find good individuals. It's based on the ratio you select in the settings and the optimal total (a big deviation from the optimal total will decrease the score). In the case of ValueError: Too many errors! less than half of the expected population size could be generated. the many backtests that were run during the generation of the initial population resulted in too many bad scores. The score is "bad":

  • if the ratio is smaller 0 meaning the backtest was not profitable.
  • if there happened none or too few (<5) trades and therefore there is no (sensible) ratio at all.
  • if the backtest raised an exception.

"But my backtest is profitable."

  • The backtest parameters could be manually overfitted and the strategy otherwise isn't good.
  • Some parameters that are optimized cause (too many) exceptions.
  • Your search space is to complex. See below.

Strategy optimization is (normally) a non-convex problem. Meaning that there isn't one solution, but multiple. Certain parameter combinations work good together leading to good results, but that same parameter value from this set that worked good combined with another works not good.

If you optimize too many variables and maybe even have logic switches like turning certain indicators on and off, the search space gets more and more complex. Making it harder / unlikely for the "solution areas" to be found.

Additionally if you switch between indicators / modes, but also have all their periods in the DNA. Not every change of DNA / a parameter is reflected in the metrics / ratio. If this only is the case for some parameters it isn't necessarily a very big issue (as this might be fixed in later iterations / mutations), but with many parameters to optimize the good solutions areas get more and more fragmented while the optimization "thinks" some parameters are good, but that's not true as their influence just wasn't reflected because that part of the code was turned off.

We learn. Too many parameters and turning parts of the strategy on and off makes it more unlikely that "solutions" are found.

Last updated: 2 years ago