Skip to content

Commit a5258bd

Browse files
committed
AverageReturnPerBarCriterion-improve-javadoc
1 parent 1f3cc76 commit a5258bd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ta4j-core/src/main/java/org/ta4j/core/criteria/AverageReturnPerBarCriterion.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@
3131

3232
/**
3333
* Calculates the average return per bar criterion, returned in decimal format.
34-
*
34+
*
3535
* <p>
36-
* The {@link ReturnCriterion gross return} raised to the power of 1 divided by
37-
* {@link NumberOfBarsCriterion number of bars}.
36+
* It uses the following formula to accurately capture the compounding effect of
37+
* returns over the specified number of bars:
38+
*
39+
* <pre>
40+
* AverageReturnPerBar = pow({@link ReturnCriterion gross return}, 1/ {@link NumberOfBarsCriterion number of bars})
41+
* </pre>
3842
*/
3943
public class AverageReturnPerBarCriterion extends AbstractAnalysisCriterion {
4044

@@ -44,6 +48,9 @@ public class AverageReturnPerBarCriterion extends AbstractAnalysisCriterion {
4448
@Override
4549
public Num calculate(BarSeries series, Position position) {
4650
Num bars = numberOfBars.calculate(series, position);
51+
// If a simple division was used (grossreturn/bars), compounding would not be
52+
// considered, leading to inaccuracies in the calculation.
53+
// Therefore we need to use "pow" to accurately capture the compounding effect.
4754
return bars.isZero() ? series.one() : grossReturn.calculate(series, position).pow(series.one().dividedBy(bars));
4855
}
4956

0 commit comments

Comments
 (0)