use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class RAVIIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal shortMA = shortSma.getValue(index);
Decimal longMA = longSma.getValue(index);
return shortMA.minus(longMA).dividedBy(longMA).multipliedBy(Decimal.HUNDRED);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class ROCIndicator method calculate.
@Override
protected Decimal calculate(int index) {
int nIndex = Math.max(index - timeFrame, 0);
Decimal nPeriodsAgoValue = indicator.getValue(nIndex);
Decimal currentValue = indicator.getValue(index);
return currentValue.minus(nPeriodsAgoValue).dividedBy(nPeriodsAgoValue).multipliedBy(Decimal.HUNDRED);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class RSIIndicator method calculate.
@Override
protected Decimal calculate(int index) {
// compute relative strength
Decimal averageGain = averageGainIndicator.getValue(index);
Decimal averageLoss = averageLossIndicator.getValue(index);
if (averageLoss.isZero()) {
if (averageGain.isZero()) {
return Decimal.ZERO;
} else {
return Decimal.HUNDRED;
}
}
Decimal relativeStrength = averageGain.dividedBy(averageLoss);
// compute relative strength index
return Decimal.HUNDRED.minus(Decimal.HUNDRED.dividedBy(Decimal.ONE.plus(relativeStrength)));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class SMAIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal sum = Decimal.ZERO;
for (int i = Math.max(0, index - timeFrame + 1); i <= index; i++) {
sum = sum.plus(indicator.getValue(i));
}
final int realTimeFrame = Math.min(timeFrame, index + 1);
return sum.dividedBy(Decimal.valueOf(realTimeFrame));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class UlcerIndexIndicator method calculate.
@Override
protected Decimal calculate(int index) {
final int startIndex = Math.max(0, index - timeFrame + 1);
final int numberOfObservations = index - startIndex + 1;
Decimal squaredAverage = Decimal.ZERO;
for (int i = startIndex; i <= index; i++) {
Decimal currentValue = indicator.getValue(i);
Decimal highestValue = highestValueInd.getValue(i);
Decimal percentageDrawdown = currentValue.minus(highestValue).dividedBy(highestValue).multipliedBy(Decimal.HUNDRED);
squaredAverage = squaredAverage.plus(percentageDrawdown.pow(2));
}
squaredAverage = squaredAverage.dividedBy(Decimal.valueOf(numberOfObservations));
return Decimal.valueOf(Math.sqrt(squaredAverage.doubleValue()));
}
Aggregations