Search in sources :

Example 66 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class IsLowestRule method isSatisfied.

@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
    LowestValueIndicator lowest = new LowestValueIndicator(ref, timeFrame);
    Decimal lowestVal = lowest.getValue(index);
    Decimal refVal = ref.getValue(index);
    final boolean satisfied = !refVal.isNaN() && !lowestVal.isNaN() && refVal.equals(lowestVal);
    traceIsSatisfied(index, satisfied);
    return satisfied;
}
Also used : Decimal(org.ta4j.core.Decimal) LowestValueIndicator(org.ta4j.core.indicators.helpers.LowestValueIndicator)

Example 67 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class FibonacciReversalIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    List<Integer> barsOfPreviousPeriod = pivotPointIndicator.getBarsOfPreviousPeriod(index);
    if (barsOfPreviousPeriod.isEmpty())
        return Decimal.NaN;
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal high = bar.getMaxPrice();
    Decimal low = bar.getMinPrice();
    for (int i : barsOfPreviousPeriod) {
        high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
        low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
    }
    if (fibReversalTyp == FibReversalTyp.RESISTANCE) {
        return pivotPointIndicator.getValue(index).plus(fibonacciFactor.multipliedBy(high.minus(low)));
    }
    return pivotPointIndicator.getValue(index).minus(fibonacciFactor.multipliedBy(high.minus(low)));
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 68 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class StandardReversalIndicator method calculateR2.

private Decimal calculateR2(List<Integer> barsOfPreviousPeriod, int index) {
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal low = bar.getMinPrice();
    Decimal high = bar.getMaxPrice();
    for (int i : barsOfPreviousPeriod) {
        low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
        high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
    }
    return pivotPointIndicator.getValue(index).plus((high.minus(low)));
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 69 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class StandardReversalIndicator method calculateS2.

private Decimal calculateS2(List<Integer> barsOfPreviousPeriod, int index) {
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal high = bar.getMaxPrice();
    Decimal low = bar.getMinPrice();
    for (int i : barsOfPreviousPeriod) {
        high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
        low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
    }
    return pivotPointIndicator.getValue(index).minus((high.minus(low)));
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 70 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class CorrelationCoefficientIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal cov = covariance.getValue(index);
    Decimal var1 = variance1.getValue(index);
    Decimal var2 = variance2.getValue(index);
    Decimal var1_2_sqrt = Decimal.valueOf(Math.sqrt(var1.multipliedBy(var2).doubleValue()));
    return cov.dividedBy(var1_2_sqrt);
}
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