Search in sources :

Example 11 with Decimal

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);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 12 with Decimal

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);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 13 with Decimal

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)));
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 14 with Decimal

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));
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 15 with Decimal

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()));
}
Also used : Decimal(org.ta4j.core.Decimal)

Aggregations

Decimal (org.ta4j.core.Decimal)92 Bar (org.ta4j.core.Bar)20 Test (org.junit.Test)8 CorrelationCoefficientIndicator (org.ta4j.core.indicators.statistics.CorrelationCoefficientIndicator)4 Trade (org.ta4j.core.Trade)3 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)3 Trade (com.github.jnidzwetzki.cryptobot.entity.Trade)2 CashFlow (org.ta4j.core.analysis.CashFlow)2 HighestValueIndicator (org.ta4j.core.indicators.helpers.HighestValueIndicator)2 LowestValueIndicator (org.ta4j.core.indicators.helpers.LowestValueIndicator)2 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)2 DifferenceIndicator (org.ta4j.core.indicators.helpers.DifferenceIndicator)1