use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StandardReversalIndicator method calculateR3.
private Decimal calculateR3(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 high.plus(Decimal.TWO.multipliedBy((pivotPointIndicator.getValue(index).minus(low))));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class CovarianceIndicator method calculate.
@Override
protected Decimal calculate(int index) {
final int startIndex = Math.max(0, index - timeFrame + 1);
final int numberOfObservations = index - startIndex + 1;
Decimal covariance = Decimal.ZERO;
Decimal average1 = sma1.getValue(index);
Decimal average2 = sma2.getValue(index);
for (int i = startIndex; i <= index; i++) {
Decimal mul = indicator1.getValue(i).minus(average1).multipliedBy(indicator2.getValue(i).minus(average2));
covariance = covariance.plus(mul);
}
covariance = covariance.dividedBy(Decimal.valueOf(numberOfObservations));
return covariance;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PeriodicalGrowthRateIndicator method getTotalReturn.
/**
* Gets the TotalReturn from the calculated results of the method 'calculate'.
* For a timeFrame = number of trading days within a year (e. g. 251 days in the US)
* and "end of day"-bars you will get the 'Annualized Total Return'.
* Only complete timeFrames are taken into the calculation.
* @return the total return from the calculated results of the method 'calculate'
*/
public double getTotalReturn() {
Decimal totalProduct = Decimal.ONE;
int completeTimeframes = (getTimeSeries().getBarCount() / timeFrame);
for (int i = 1; i <= completeTimeframes; i++) {
int index = i * timeFrame;
Decimal currentReturn = getValue(index);
// Skip NaN at the end of a series
if (currentReturn != Decimal.NaN) {
currentReturn = currentReturn.plus(Decimal.ONE);
totalProduct = totalProduct.multipliedBy(currentReturn);
}
}
return (Math.pow(totalProduct.doubleValue(), (1.0 / completeTimeframes)));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class ConvergenceDivergenceIndicator method calculateNegativeConvergence.
/**
* @param index the actual index
* @return true, if negative convergent
*/
private Boolean calculateNegativeConvergence(int index) {
CorrelationCoefficientIndicator cc = new CorrelationCoefficientIndicator(ref, other, timeFrame);
boolean isConvergent = cc.getValue(index).isGreaterThanOrEqual(minStrenght);
Decimal slope = calculateSlopeRel(index);
boolean isNegative = slope.isLessThanOrEqual(minSlope.abs().multipliedBy(Decimal.valueOf(-1)));
return isConvergent && isNegative;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class ConvergenceDivergenceIndicator method calculateNegativeDivergence.
/**
* @param index the actual index
* @return true, if negative divergent
*/
private Boolean calculateNegativeDivergence(int index) {
CorrelationCoefficientIndicator cc = new CorrelationCoefficientIndicator(ref, other, timeFrame);
boolean isDivergent = cc.getValue(index).isLessThanOrEqual(minStrenght.multipliedBy(Decimal.valueOf(-1)));
if (isDivergent) {
// If "isDivergent" and "ref" is positive, then "other" must be negative.
Decimal slope = calculateSlopeRel(index);
return slope.isLessThanOrEqual(minSlope.abs().multipliedBy(Decimal.valueOf(-1)));
}
return false;
}
Aggregations