File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
ta4j-core/src/main/java/org/ta4j/core/criteria Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 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 */
3943public 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
You can’t perform that action at this time.
0 commit comments