ta4j icon indicating copy to clipboard operation
ta4j copied to clipboard

[BUG] error in calculation of ReturnOverMaxDrawdownCriterion

Open dev590t opened this issue 3 years ago • 4 comments

I have checked existing issues and wiki

Describe the bug I have a strategy A that make 11.13866501343252% return, and 0.5954536310601489% Max. Drawdown ReturnOverMaxDrawdownCriterion give

dev_1-bin@ 1.1113866501343252 / 0.005954536310601489 
res0: Double = 186.64537289924766

I have a strategy B that make 0.41164363422523% return, and 0.52925610114672155% Max. Drawdown ReturnOverMaxDrawdownCriterion give

dev_1-bin@ 1.0041164363422523 / 0.0052925610114672155 
res1: Double = 189.72222222222223

It is evident strategy A is much better thant strategy B

// strategy A
dev_1-bin@ (1.1113866501343252 - 1) / 0.005954536310601489 
res2: Double = 18.706183710058472
//strategy B
dev_1-bin@ (1.0041164363422523 - 1) / 0.0052925610114672155 
res3: Double = 0.7777777777777891

But ReturnOverMaxDrawdownCriterion indicates strategy B is a little better strategy A ReturnOverMaxDrawdownCriterion shouldn't use GrossReturnCriterion in its calculation https://github.com/ta4j/ta4j/blob/369cadd448df3935745f96c5e5c0b712ad0a96c6/ta4j-core/src/main/java/org/ta4j/core/analysis/criteria/ReturnOverMaxDrawdownCriterion.java#L40

dev590t avatar Sep 19 '21 22:09 dev590t

In https://github.com/ta4j/ta4j/blob/369cadd448df3935745f96c5e5c0b712ad0a96c6/ta4j-core/src/main/java/org/ta4j/core/analysis/criteria/ReturnOverMaxDrawdownCriterion.java#L60 I think we should replace by

            final Num totalProfit = grossReturnCriterion.calculate(series, tradingRecord) - 1;

dev590t avatar Sep 20 '21 07:09 dev590t

I think a better solution could be add a new indicator GrossReturnPercentCriterion such as GrossReturnPercentCriterion = GrossReturnCriterion - 1

And replace https://github.com/ta4j/ta4j/blob/369cadd448df3935745f96c5e5c0b712ad0a96c6/ta4j-core/src/main/java/org/ta4j/core/analysis/criteria/ReturnOverMaxDrawdownCriterion.java#L60 by

            final Num totalProfit = grossReturnPercentCriterion.calculate(series, tradingRecord) ;

I propose add a new indicator GrossReturnPercentCriterion because I think this value can be util for other analysis.

dev590t avatar Sep 20 '21 12:09 dev590t

@dev590t would you be willing to contribute a PR to implement this?

TheCookieLab avatar Apr 12 '23 23:04 TheCookieLab

GrossReturnPercentCriterion such as GrossReturnPercentCriterion = GrossReturnCriterion - 1

Please note, that we can now use addBase:

https://github.com/ta4j/ta4j/blob/35d6dd2f2dc17f2b4f4ebcf8025f767492a369d2/ta4j-core/src/main/java/org/ta4j/core/criteria/pnl/ReturnCriterion.java#L46

It is evident strategy A is much better thant strategy B

Well, it is evident according to another criterion (e.g. ProfitCriterion), but not to the actual criterion (ReturnOverMaxDrawdownCriterion).

It would be nice to update this issue and let us know what exactly you want so we can improve ReturnOverMaxDrawdownCriterion.

nimo23 avatar Jun 17 '23 11:06 nimo23