Optimization criteria: integral of "underwater"

Avatar
  • updated
  • Under review

Can we have an optimization criteria that penalties the integral of the min(equity curve, balance) that is below the max balance of the test?

Avatar
0
Andrey Khatimlianskyi
  • Under review

Interesting idea! Do you have formula for this?

Avatar
0
Hannes Waser

Sure.

variant 1) w=sum(d_i) where d_i is an equity measure that is lower than max balance up to the time i

then the optimization criteria is something like total_gain/w

Note: Measurements ABOVE the max balance up to time sample i are ignored and are not part of the sum.

variant 2 (generates smoother equity curved)

w=sum(r_i) where r_i is the measurement that is below the *fitted line* from the start to the last equity. 

Note: Measurements ABOVE the fitted line are ignored and are not part of the sum.

the penalty can then also be total_gain/w

consider also gain/(1+w) just in case w is zero.

or gain/ln(2+w)

let me know if I can clarify more

Avatar
0
Andrey Khatimlianskyi
Quote from Hannes Waser

Sure.

variant 1) w=sum(d_i) where d_i is an equity measure that is lower than max balance up to the time i

then the optimization criteria is something like total_gain/w

Note: Measurements ABOVE the max balance up to time sample i are ignored and are not part of the sum.

variant 2 (generates smoother equity curved)

w=sum(r_i) where r_i is the measurement that is below the *fitted line* from the start to the last equity. 

Note: Measurements ABOVE the fitted line are ignored and are not part of the sum.

the penalty can then also be total_gain/w

consider also gain/(1+w) just in case w is zero.

or gain/ln(2+w)

let me know if I can clarify more

Something similar to R-squared, but ignoring the up-side, right?

Or do you want to take only one d_i after each new balance maximum?

Why to analyze balance and not a previous equity maximum?

Can you make some draft in Excel (better on Google Drive) so we can discuss it with real example?

Avatar
0
Hannes Waser

Good question: I indeed use the equity and not balance (just checked my code).
Balance would eventually be better, because it would not penalize times when equity is higher than the balance.

Have a look at this code. It expects an array of ALL equity sample points from the whole backtest (so I track these somewhere else)

r2UnderWater.mqh

Avatar
0
Andrey Khatimlianskyi
Quote from Hannes Waser

Good question: I indeed use the equity and not balance (just checked my code).
Balance would eventually be better, because it would not penalize times when equity is higher than the balance.

Have a look at this code. It expects an array of ALL equity sample points from the whole backtest (so I track these somewhere else)

r2UnderWater.mqh

I have similar code to collect equity values.

What's the next step? How to calculate integral of "underwater" given the array of equity values?