optimization with zero equity results in too much fitness value
optimization with zero equity results in too much fitness value
10 Jun 2019, 09:57
Dear cTrader Team,
when running optimization on data from several months, it happens that some simulations crash the account (equity goes to zero) while others finish the simulation and provide a final balance. This is totally fine, because some simulations just take too much risk. What's not fine is that the crashed simulations result in a much higher fitness level than the sims that made it to the end. This happens with Genetic Algorithm.
I tried different optimization criteria, but can't stop this behavior. Only solution I see is to write my own fitness calculation, but to get reliable results is not that easy. It would be much easier if your algorithm stops rating failed simulations so high. Looks like a bug to me. See the attached picture. That shows a perfect example for my problem.
I can sort out the bad simulation by hand, but not when they are so many. The genetic algorithm gets misguided this way and optimizes for wrong parameter settings.
What is your suggestion top fix this problem for me?
Kind Regards
Replies
PureForm
10 Jun 2019, 12:20
( Updated at: 21 Dec 2023, 09:21 )
Hey Panagiotis,
that did the trick for now.
But now that I can't use Sharpe or Sortino Ratio, it's harder to optimize for risk taken.
The problem still persists: Simulations that did not finish (DNF) get a ridiculously high profit factor, sharpe ratio and sortino ratio although they crashed my account. For my understanding that is the worst possible outcome of a simulation. How can I filter out these sims? Is there some kind of DNF flag I can use? Something I can put into the OnStop() function to kill the fitness factor of this particular simulation?
Thanks for your help
@PureForm
PanagiotisCharalampous
10 Jun 2019, 14:38
Hi PureForm,
Any chance we can get the cBot code and your optimization parameters so that we can have a look?
Best Regards,
Panagiotis
@PanagiotisCharalampous
brikulskiiroman
17 Nov 2020, 14:58
RE:
I assume this is the reason why you also have a high physical value. I advise you to remove it from the criteria and try again
PureForm
17 Nov 2020, 22:37
Well, I added some small code to all my bots which closes all positions when equity drops below 20% and then stops the bot. This is the quick und clean solution.
The problem is, when equity drops to zero, the simulation leaves all positions open. This leads to totally wrong fitness calculation, because only the good (closed) trades get calculated, while the bad positions are still open and ingored.
This misbehavior expands to other situations, e.g. your simulation finishes, but open positions don't get closed. So now you see a profit percent which doesn't take the open positions into account. Your real profit may be negative, but simulation shows a positive outcome, all because of unclosed positions. I expect a simulation to start with zero open positions and also finishes this way.
Later on I wrote my own fitness calculation which rewards good money management, but nowadays I don't use optimization anymore. I wrote some code which calculates backtests right in the trading window. This is much faster than an optimization run. This indicator draws statistical analysis right into the trading window and when I change a parameter the backtest result gets calculated in 10 seconds. It also implements swap fees, something neither backtest nor optimization calculate. When I am happy, I can still run a tick data backtest but I ignore the in-built backtest results completely. My bot takes over and calculates the results itself (including swap fees etc.).
It's a pitty cTrader doesn't backtest properly, but now that I invested all this effort I am completely set up and I don't mind it anymore, plus I look forward to every new update which pushes cTrader even further. cTrader is good enough for me now and it will only get better in the future.
@PureForm
PanagiotisCharalampous
10 Jun 2019, 10:28
Hi PureForm,
From what I can see the specific set of parameters have a high Sortino Ratio. I assume that is the reason you have a high fitness value as well. Can you remove it from the criteria and try again?
Best Regards,
Panagiotis
@PanagiotisCharalampous