Search in sources :

Example 16 with Decimal

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

the class WilliamsRIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    HighestValueIndicator highestHigh = new HighestValueIndicator(maxPriceIndicator, timeFrame);
    LowestValueIndicator lowestMin = new LowestValueIndicator(minPriceIndicator, timeFrame);
    Decimal highestHighPrice = highestHigh.getValue(index);
    Decimal lowestLowPrice = lowestMin.getValue(index);
    return ((highestHighPrice.minus(indicator.getValue(index))).dividedBy(highestHighPrice.minus(lowestLowPrice))).multipliedBy(multiplier);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 17 with Decimal

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

the class AverageProfitableTradesCriterion method calculate.

@Override
public double calculate(TimeSeries series, Trade trade) {
    int entryIndex = trade.getEntry().getIndex();
    int exitIndex = trade.getExit().getIndex();
    Decimal result;
    if (trade.getEntry().isBuy()) {
        // buy-then-sell trade
        result = series.getBar(exitIndex).getClosePrice().dividedBy(series.getBar(entryIndex).getClosePrice());
    } else {
        // sell-then-buy trade
        result = series.getBar(entryIndex).getClosePrice().dividedBy(series.getBar(exitIndex).getClosePrice());
    }
    return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d;
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 18 with Decimal

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

the class AverageProfitableTradesCriterion method calculate.

@Override
public double calculate(TimeSeries series, TradingRecord tradingRecord) {
    int numberOfProfitable = 0;
    for (Trade trade : tradingRecord.getTrades()) {
        int entryIndex = trade.getEntry().getIndex();
        int exitIndex = trade.getExit().getIndex();
        Decimal result;
        if (trade.getEntry().isBuy()) {
            // buy-then-sell trade
            result = series.getBar(exitIndex).getClosePrice().dividedBy(series.getBar(entryIndex).getClosePrice());
        } else {
            // sell-then-buy trade
            result = series.getBar(entryIndex).getClosePrice().dividedBy(series.getBar(exitIndex).getClosePrice());
        }
        if (result.isGreaterThan(Decimal.ONE)) {
            numberOfProfitable++;
        }
    }
    return ((double) numberOfProfitable) / tradingRecord.getTradeCount();
}
Also used : Trade(org.ta4j.core.Trade) Decimal(org.ta4j.core.Decimal)

Example 19 with Decimal

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

the class MaximumDrawdownCriterion method calculate.

@Override
public double calculate(TimeSeries series, TradingRecord tradingRecord) {
    CashFlow cashFlow = new CashFlow(series, tradingRecord);
    Decimal maximumDrawdown = calculateMaximumDrawdown(series, cashFlow);
    return maximumDrawdown.doubleValue();
}
Also used : CashFlow(org.ta4j.core.analysis.CashFlow) Decimal(org.ta4j.core.Decimal)

Example 20 with Decimal

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

the class CMOIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal sumOfGains = Decimal.ZERO;
    for (int i = Math.max(1, index - timeFrame + 1); i <= index; i++) {
        sumOfGains = sumOfGains.plus(gainIndicator.getValue(i));
    }
    Decimal sumOfLosses = Decimal.ZERO;
    for (int i = Math.max(1, index - timeFrame + 1); i <= index; i++) {
        sumOfLosses = sumOfLosses.plus(lossIndicator.getValue(i));
    }
    return sumOfGains.minus(sumOfLosses).dividedBy(sumOfGains.plus(sumOfLosses)).multipliedBy(Decimal.HUNDRED);
}
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