Are Evolutionary Algorithms Useful?

There is statistical evidence that Marchus (@Whycliffes) has a good model:Two Pre-Registered Designer Models on OSF - #28 by Jrinne. Specifically he has one of the models in a set of 3 models with a FDR of 0.2 measuring the excess returns over the last 2 years.

To be clear the BH model to determine this is limited to the last 2 years for excess returns. I think other models would also do well if the period of excess returns could be extended. Also there were some assumptions made regarding the volatilities of the model's excess returns as weekly excess returns or the volatility of the excess returns is not provided P123's download of Designer Models. This weakness would be eliminated if P123 provided the weekly excess returns for designer models as a download or even if they provided the standard deviation of the weekly excess returns in the Designer Model Download. Maybe with options of greater than 2 years for excess returns if P123 wishes to facilitate statistical methods for evaluating Designer Models and newer methods.

It bears repeating that only the last 2 years could be tested due to the limitations of the data.

That having been said, he had the top model: https://www.portfolio123.com/app/r2g/summary?id=1764562. And advanced Machine Learning methods have a relatively short history at P123 anyway.

Marchus, in the past you have said you use evolutionary algorithms including genetic algorithms and CMA-ES:ML Script Performance vs. Genetic Algorithms & CMA-ES**

I would be interested in anything you wish to share about your method for this model including whether you are still using evolutionary algorithms.

Thanks in advance for sharing anything you are comfortable sharing.

Jim

Useful, with a caveat your FDR framing already points at: an evolutionary algorithm is an optimization loop wrapped around a backtest, and every generation is another look at the same data. The fitness of the final champion tells you very little on its own — it is the survivor of thousands of implicit comparisons against the same history.

The cheapest guardrail I have found is almost embarrassingly simple: before the optimizer ever runs, write down the fitness function, the constraints, and the pass/fail thresholds — timestamped — and lock the out-of-sample window the winner will be judged on. Once that is frozen, the optimizer is free to do its thing. The champion then gets exactly one look at the holdout: it either clears the pre-registered bar or it does not.

What this buys is not better models; it is an honest denominator. Your BH/FDR analysis does the same job from the statistical side. Pre-registration does it from the process side, and it costs nothing except the discipline of deciding what "good enough" means before you know the answer.

Nice. Very nice!. Maybe 3 great ideas expressed here if I understand. The multiple comparison problem, the holdout test sample and maybe de Prado's deflated Sharpe ratio (or something similar) that keeps track of the number of trials: your denominator reference. The BH does this too.

I recently had some experience with de Prado's Sharpe ratio here: Claude Artifact

It seemed to work well, but correlation of the trials had to be addressed.

One thing I'd add on the trial count going into the deflated Sharpe: the formula is only as honest as the number of independent trials you feed it. When trials run on overlapping data or correlated features, the nominal count overstates how many independent bets were actually placed, and the deflated Sharpe comes out flattering.

What I do before plugging anything in: cluster the trial return series by correlation first, then use the effective independent trial count — roughly the number of clusters that genuinely disagree with each other — instead of the raw count. It's a rough estimate, but it stops the denominator from lying to you.

Curious where you land: in your experience, does the deflated Sharpe catch more false positives than a reality-check style correction, or is it the other way around?

My experience with the deflated Sharpe ratio is new and so far it has been limited to the above Claude Artifact. I was impressed. I thought it gave real insight into the discussion of momentum which has a countable number of possible SMA values—all of which I tried (and counted) with automation.

To date, I have relied more on validation methods and test samples. I plan to use the deflated Sharpe ratio more.

Thanks for sharing this — the exhaustive-SMA-grid point is exactly where I think the deflated Sharpe earns its keep. Trying every countable SMA value with automation is the honest version of what most people do quietly by hand: the number of configurations tried is the real multiple-testing budget, whether or not anyone writes it down. I'm curious how you draw the line between your validation samples and the final test sample when the grid is that large. Do you freeze the chosen SMA configuration before it ever sees the test data, or do you allow a limited second look? That's the part of the discipline I find hardest to keep clean in practice.

So there is no rational controversy over whether to use time-series validation or a walk-forward analysis (WFA). Some have noted that an expanding window is better than a rolling window and I find that to be true. But a walk-forward backtest can use either (expanding window or rolling window).

But here is the thing. A walk-forward backtest or time-series validation can test either a parameters OR or a single algorithm.

Here is my algorithm in this artifact with no internal parameters: For each training period find the best SMA within training data only and then test the next period (with no data leakage). Expand the window and repeat. But the algorithm has no variables or parameters.

This makes it like nested cross-validation. For nested cross-validation with more than one parameter, one would use k-fold validation in the training period allowing you to use validation to select a parameter (when you have more than one) and then use a true test sample and walk that forward.

Scikit-learn addresses your very legitimate concerns about regular validation methods here I believe: Nested versus non-nested cross-validation

Nested cross-validation has been discussed before by @jlittleton: Walk forward time series testing with inner kfold loop for AI training. I guess I was the only one to give it a heart at the time (Nov 24).

The upshot of this is I have no need for published papers or other people's cherry-picked examples (with no sharing of the number of trials in either case). With modern automation I have done an exhaustive search of the entire SMA cross-over space and have the final answer on whether it works or not as far as I am concerned. Deflated Sharpe ratio confirming my finding.

This entire discussion is over my head. I don't know what an FDR is or what a BH is or what a deflated Sharpe ratio is. SMA, I assume, is simple moving average, but how that enters into this is beyond me.

Does any of this apply to manual optimization of ranking systems? Or is this all about using P123's AI factors? Or something else? I'm trying to figure out whether there's anything here that would be of use to me as an optimizer of ranking systems using what I consider robust methods.

I am also interested in this topic, and so looked up the definitions. BH and FDR are described in the first link in the opening post. Deflated Sharpe ratio is defined in a paper available online.

These are adjustments made to account for multiple tests run on the same data set. If p-values and statistical testing is important, consider using the Benjamini–Hochberg procedure (BH) to adjust for multiple tests.

Running multiple backtests has a reversion to the mean problem. Some of the variation will be random, and so just picking the screen with the highest return will often disappoint. The deflated Sharpe ratio paper discusses this in detail.

de Prado's deflated Sharpe ratio [1] adjusts the Sharpe ratio for:
The number of independent trials carried out
the variance of the backtest results
the sample length
the skewness and kurtosis of the returns

  1. Bailey, David H. and López de Prado, Marcos, The Deflated Sharpe Ratio: Correcting for Selection Bias, Backtest Overfitting and Non-Normality (July 31, 2014).
    https://www.davidhbailey.com/dhbpapers/deflated-sharpe.pdf

=== links ===

OK, I guess this does apply to optimizing ranking systems. What concerns me far more than Type I errors are Type II errors, which would render the FDR irrelevant.

For example, let's say I'm testing two hundred factors, some of which have serious flaws or can't really work very well (type I errors). And let's say there are ten or twenty factors that would make a huge difference but aren't in my set of factors (type II errors). Incorporating some of the type I factors in my ranking system is far less harmful to the out-of-sample results than neglecting some of the type II factors.

But maybe I'm on the wrong track here.

Here's what I really didn't understand:

What is the "fitness function"? What do you mean by the "constraints"? What is the "pass/fail threshold"? These seem to me like useful ideas, but I have no idea how to implement them.

Also, I'm still uncertain where simple moving averages (SMAs) come into play here.

I'm not a believer in Sharpe ratios, so that's not relevant to me personally, though I can see how it might be useful for some people. In my research, Sharpe ratios have very little persistence compared to other measures I use.

Yuval — fair questions; let me make each one concrete.

Fitness function: the single number the optimizer may maximize on the training window — e.g., net annualized return after costs. Declared before the optimizer runs. The choice of metric matters less than the fact that it's fixed in advance, not picked afterward from whatever looked best.

Constraints: hard disqualifiers — max drawdown cap, minimum trade count, turnover ceiling. A champion breaching any of these is rejected regardless of fitness. They're the "not allowed to win by cheating" rules.

Pass/fail threshold: the pre-registered bar on the locked holdout, e.g. "must beat the benchmark by ≥ X on the frozen window." One look: it clears the bar or goes back to research, no second tuning pass.

SMAs: they're the concrete search space. Jrinne's exhaustive SMA automation is the honest version of what most people do quietly by hand — and here the grid is declared upfront, with every SMA value tried counted as a "look" in the testing budget. That's where your FDR/BH machinery meets pre-registration: the same denominator, counted two ways.

On Type I vs Type II — you're right, and it's a real limit: pre-registration makes Type I honest and auditable, but it can't conjure the missing twenty factors. Which candidates to test is a domain-knowledge question; pre-registration only governs how you test them. And noted on Sharpe — the apparatus is metric-agnostic; use whatever persists in your research.

You have complete control over Type I and Type II errors in statistics by choosing where to set your significance threshold. If you want fewer Type II errors, you increase your threshold—it’s just a trade-off, not a flaw in statistics. In fact this is the only way to set your desired level of Type II errors (whatever level you may choose). The alternative is to not know how many Type I or Type II errors there are (with no control of either).

By that I mean you have the option to set threshold at p-value < 0.1 or p-value < 0.2 if you want. Even higher. Misunderstanding that trade-off is usually the real problem.

The exact same dynamic applies here. We talk a lot about the False Discovery Rate (FDR)—which is essentially your false positives among accepted models—but there is also the False Omission Rate (FOR), which acts just like a Type II error for the models you discard.

If you want fewer FORs (fewer missed gems), you have to accept the expense of more FDRs (more noise/false positives) by adjusting your threshold.

The alternative is operating with zero understanding and zero control of the number of FDR or FOR, which is pretty much our present situation.

I also find the Sharpe ratio is not the best predictor for the screens I work with.

I'm not sure what p-value (or confidence level) to use. The standard 95% confidence level (5% chance of type I errors) seems too high for my screens. I am mostly concerned about type I errors with my process, and that simplifies things. The confidence level could be viewed as a risk measure. I am willing to accept lower confidence for higher returns. Error bars might be better for setting expectations.

The fitness function is part of the Evolutionary Algorithm process. The idea is to run many tests, and then use the fitness function to choose the best results.

SMA is just a simple example using simple moving averages.

These replies are very helpful indeed.

I developed my testing/optimization procedure, which is indeed evolutionary in many senses, on my own, without any knowledge of any of these standard procedures and terms. It would take a great deal of space to explain the whole thing here, and I'm not sure if it would be at all helpful. But I believe that it's consonant, on a basic level, with what you're doing, even if I don't have a way of measuring type I and type II errors, or constraints or pass/fail thresholds. I think those are more or less built in to my procedure, but I could be wrong.

I do have some principles that seem to have served me well (I have an 11-year CAGR of over 40% without a single negative year). They include:

  • Never test the actual system you'll use to buy and sell stocks, and never test on the entire universe you're using. The actual system should be a composite of smaller, more local tests.
  • Always trim outliers from your results, and trim them heavily.
  • Use "correlation tests" to determine procedures. Apply the testing procedures that produce the best correlation between in-sample and out-of-sample results. This goes for, e.g., which fitness function to use, how many stocks to test, how long to backtest, and so on. When doing these correlation tests, always use systems that have not been optimized or backtested, ever.
  • Conceive of all testing as probabilistic. The object of a test is not to determine a probable result but to determine the result most probable to succeed out of sample. That's why constraints and thresholds don't work for me: it's entirely possible that no system will pass, and in that case you still want to choose the best system from the failed ones.
  • Always use realistic slippage in backtesting. Testing without realistic slippage can be fatal.

One thing I've noticed with evolutionary testing is that two procedures that differ in relatively insignificant ways can lead to entirely different results, each as good as the other. This is the magic of evolution: one ancestral species can end up giving rise to a number of descendant species, each one successful in exactly the same environment. Optimizing so that this happens naturally is far better IMO than testing every single combination.

Most of the optimization methods people used until relatively recently at P123 were evolutionary algorithms by definition. Specifically, many would (and still do) start with a set of weights for the rank features, randomly perturb some of them, test the new ranking system, and if it improves upon the baseline, keep the new weights and repeat. That iterative variation-and-selection loop is a textbook evolutionary algorithm.

The fact that these manual workflows are evolutionary algorithms was discussed as early as 2018 in this forum. @InspectorSector made available a spreadsheet that automated an evolutionary algorithm to some extent and it is discussed here

This is also the thread where Miro asks for the information ratio.

More formal evolutionary methods simply structure that search more efficiently:

  • CMA-ES (Covariance Matrix Adaptation Evolution Strategy) guides the search by updating a covariance matrix of the feature weights across generations rather than mutating weights blindly.

  • Genetic algorithms use crossover (recombination) alongside mutation, which preserves beneficial "building blocks" of features together and does a better job of finding interactions.

BTW, one reason the Sharpe ratio is not ideal is that it does not strip out market noise. Benchmarking against the universe and taking excess returns removes that common market component—a form of what Lopez de Prado calls de-noising. That is a key reason the Information Ratio (excess return divided by tracking error) is often a much cleaner objective function.

The information ratio is just de-noising the Sharpe ratio in de Prado's terminology.

Congratulations to @Whycliffes for the successful implementation of modern versions of the evolutionary algorithm.

Yuval — thanks for laying out the process; the six principles read like a checklist earned the hard way. Three places where it rhymes with what we run every day:

  1. On never testing the system you're running live: we keep two ledgers — the backtest book and the live book — and a parameter tuned in one is never graded in the other. Backtest has no bad months; live does. And live means real slippage, which is why the live ledger is the only grade that counts.

  2. On the correlation test and everything-is-probabilistic: we've run the same match through two models on the same data layer and watched it score 75 under one and 35 under the other — small procedural differences, wildly different out-of-sample behavior. The data wasn't the difference; the tuning layer was. That's why we say the moat is in the parameters, not the signals.

  3. On heavy winsorizing: we treat outliers as information about the pricing regime rather than noise to delete — but the model has to earn the right to see them: the trigger threshold filters out everything whose evidence isn't strong enough first, which does the winsorizing at the gate instead of inside the model.

One question back: on never testing the system you're running — do you freeze the procedure at launch (no parameter updates from live performance at all), or can live evidence evolve the procedure as long as the evolution itself is pre-registered?

(emphasis mine)

NIce! Extremely disciplined validation method!

Live performance doesn't play any part in optimization, with a caveat: it might inspire the introduction of new factors or new twists in managing the portfolio, which will then be introduced in the next optimization.

But at what cost?

Averaging a bunch of very disparate evolutionary results will give you a much richer ranking system than one that is overoptimized.

I hate to quote Claude because I hate reading AI-generated prose (and it's easy to tell). Nonetheless:

You’re right that the usual perturb-and-test approach is an evolutionary algorithm. Mine is one too. I randomly change about ten factor weights in the best systems, test the results, keep the winners, and repeat. I run two families in parallel, one with weights in steps of 2 and one in steps of 2.5. They reach similar alpha with quite different factors.

That last point is why I’m not convinced CMA-ES or genetic algorithms would help much. If very different weightings work about equally well, there’s no single peak to find, and a smarter search just gets you to “about as good” faster. Backtests are also noisy, and a method that learns which changes “worked” will tend to follow lucky ones. Random changes tested on several separate universes are cruder but harder to fool.

I’m also not after one best system. I take the winners from five random universes and average them, because leaving out a factor that works costs more than including one that doesn’t. Formal optimizers are built to converge on a single answer, which works against that.

For noisy microcap backtests, I think how you pick the winners matters more than how you generate the candidates.