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);
}
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;
}
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();
}
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();
}
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);
}
Aggregations