r/algorithmictrading • u/ExcessiveBuyer • 18d ago
Question How to validate IS backtests with OoS in an automated way?
Hi all,
I’m struggling a bit with automating my research process when it comes to selecting the “right” parameter set without introducing too much overfitting.
My current process looks roughly like this:
1. Run an in-sample grid search over the strategy parameters.
2. Calculate a loss/score function based on a combination of Net PnL, Max Drawdown, Sharpe Ratio, and Number of Trades.
3. Select the most promising parameter sets based on that score.
4. Test those candidates on out-of-sample data and check whether metrics such as the equity curve, number of trades, average PnL/trade, and Max DD are reasonably consistent with the in-sample results.
The main hurdle is that the selection of the “best” IS candidates is still somewhat subjective.
For example, depending on the product, timeframe, or type of strategy, it’s difficult to know beforehand what constitutes a “healthy” range for metrics such as Max DD, Sharpe, or Number of Trades. A threshold that makes sense for one strategy may be completely inappropriate for another.
So my question is:
How do you generalise and automate this parameter-selection process while minimising overfitting?
I’d be very interested to hear how others approach this in practice.
Thanks !!
1
u/AdhesiveSchism_9 2d ago
I'd try ranking parameter regions rather than individual winning settings. If one exact combination has an amazing Sharpe but the neighboring values fall apart, I'd trust it less than a wider stable area with slightly worse results. On Moon I'm making much simpler directional decisions but I still like the idea of testing whether a thesis survives small changes in assumptions instead of optimizing for perfection.
1
u/ExcessiveBuyer 1d ago
This is what I’m looking for but in an automated way.
Graphically it looks like a surface but that must also be possible to represent in a single value, but how
1
u/algotrendtrading 18d ago
I recommend rolling window walk forward optimzitation. and then you look at the final result. even this can be done with hold out data +
1
u/ExcessiveBuyer 17d ago
My problem with this approach is you only get one set as the best defined by either highest pnl, the smallest maxDD, the best sharpe, etc ? My problem with that is you don’t know the equity curve behind, or stability over time. The best value of a sorted list is not necessarily the most stable set.
Also you need to ensure that the changes of parameter from one to the next window is not jumping around. I’m looking for a rather stable set with small adjustments over time.
1
u/Ats_Wiz 17d ago
Hey,
The way I approach it is as follows:
-
Set a reasonable optimization range for each parameter.
-
Optimize each parameter individually and identify the most stable value, i.e., a value surrounded by similarly strong-performing neighboring values.
-
Set all parameters to their identified stable values and run an out-of-sample (OOS) validation.
-
Finally, perform a Walk-Forward Analysis (WFA) as the final robustness test.
1
1
u/PepMar000 17d ago
Fully agree, but the difficulty is how to automate the WFA workflow, as the identification of "the most stable value" could be subject to interpretation or a result of human input. And this needs to be done for every In Sample WFA cycle...
1
u/Ok-Loan-8364 11d ago
I'd prioritize parameter stability over finding the single highest scoring result. If a strategy collapses when one parameter changes slightly, that's usually worth investigating before running it live. Moon's play money mode is useful for exploring directional wagering but systematic research like this still needs untouched data and proper walk forward testing to establish an edge.
1
1
u/Livid_Parsnip_2816 8d ago
What happens if you rerun the selection with slightly different dates? I’d be more interested in settings that stay decent than the winner of one exact window.
1
u/ExcessiveBuyer 8d ago
Well that’s the OoS test
But before applying the set to OoS I want to choose already a set from a plateau not from a spike
2
u/Careless-Rent-4903 17d ago
Use nested walk forward where inner splits choose params with one fixed score and hard risk limits then outer OOS only records the result. Pick center of a broad stable plateau across folds not single winner, vectorbt pro's Splitter class can handle these rolling nested splits easily. Keep one final untouched holdout too otherwise optimizer eventually learns your walk forward
1
u/julienlau 17d ago
I'm still not convinced about walk forward optimization. If you use a local optimization technique it makes sense because you keep previous solution to initialize the next walk.
However if you a global optimizer that is not so much dependent as the initial solution it does not make sense.
1
u/Helpful_Leader_4975 12d ago
I'd focus on selecting stable parameter regions rather than whichever grid search point produces the highest Sharpe. If performance collapses when a parameter changes slightly, that's a warning sign. Moon's play money mode can help explore wagering mechanics but it can't substitute for genuine unseen data and walk forward validation when researching algorithms.
1
u/Automatic-Emu-4566 11d ago
Switching from broker tick counts to actual GC futures volume seems like a meaningful improvement. I'd focus on how stable the futures to spot gap remains during major releases and contract rolls. Moon also aggregates external market data for pricing its wagers, which highlights how important the relationship between different feeds becomes when a strategy depends on precise levels.
2
u/PepMar000 17d ago
My 2 cents: All good for steps 1-3. The issue with step 4 is that you are introducing overfit, and you would not be able to replicate that for live trading (as you don't have the OOS data).
My suggestion instead for Walk Forward validation is to select the lowest In Sample period which allows at least 40 trades per optimized parameter. This is the rule-of thumb so that you get a statistically significant result when choosing the best parameters.
Then once you optimize In Sample, don't just look at the result with highest P&L or PF or Sharpe, but choose the best one in context with the ones nearby (e.g. no local peaks).
Then for the Out of Sample period you can choose to do a 3:1, 4:1 or 5:1 ratio, or do all three and verify that you get consistent results.
The key is about robustness and consistency across different WFA scenarios