use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PriceVariationIndicatorTest method indicatorShouldRetrieveBarVariation.
@Test
public void indicatorShouldRetrieveBarVariation() {
assertDecimalEquals(variationIndicator.getValue(0), 1);
for (int i = 1; i < 10; i++) {
Decimal previousBarClosePrice = timeSeries.getBar(i - 1).getClosePrice();
Decimal currentBarClosePrice = timeSeries.getBar(i).getClosePrice();
assertEquals(variationIndicator.getValue(i), currentBarClosePrice.dividedBy(previousBarClosePrice));
}
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StopGainRuleTest method isSatisfied.
@Test
public void isSatisfied() {
final Decimal tradedAmount = Decimal.ONE;
// 30% stop-gain
StopGainRule rule = new StopGainRule(closePrice, Decimal.valueOf("30"));
assertFalse(rule.isSatisfied(0, null));
assertFalse(rule.isSatisfied(1, tradingRecord));
// Enter at 108
tradingRecord.enter(2, Decimal.valueOf("108"), tradedAmount);
assertFalse(rule.isSatisfied(2, tradingRecord));
assertFalse(rule.isSatisfied(3, tradingRecord));
assertTrue(rule.isSatisfied(4, tradingRecord));
// Exit
tradingRecord.exit(5);
// Enter at 118
tradingRecord.enter(5, Decimal.valueOf("118"), tradedAmount);
assertFalse(rule.isSatisfied(5, tradingRecord));
assertTrue(rule.isSatisfied(6, tradingRecord));
assertTrue(rule.isSatisfied(7, tradingRecord));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StopLossRuleTest method isSatisfied.
@Test
public void isSatisfied() {
final Decimal tradedAmount = Decimal.ONE;
// 5% stop-loss
StopLossRule rule = new StopLossRule(closePrice, Decimal.valueOf("5"));
assertFalse(rule.isSatisfied(0, null));
assertFalse(rule.isSatisfied(1, tradingRecord));
// Enter at 114
tradingRecord.enter(2, Decimal.valueOf("114"), tradedAmount);
assertFalse(rule.isSatisfied(2, tradingRecord));
assertFalse(rule.isSatisfied(3, tradingRecord));
assertTrue(rule.isSatisfied(4, tradingRecord));
// Exit
tradingRecord.exit(5);
// Enter at 128
tradingRecord.enter(5, Decimal.valueOf("128"), tradedAmount);
assertFalse(rule.isSatisfied(5, tradingRecord));
assertTrue(rule.isSatisfied(6, tradingRecord));
assertTrue(rule.isSatisfied(7, tradingRecord));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class MedianPriceIndicatorTest method indicatorShouldRetrieveBarClosePrice.
@Test
public void indicatorShouldRetrieveBarClosePrice() {
Decimal result;
for (int i = 0; i < 10; i++) {
result = timeSeries.getBar(i).getMaxPrice().plus(timeSeries.getBar(i).getMinPrice()).dividedBy(Decimal.TWO);
assertEquals(average.getValue(i), result);
}
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class CachedIndicatorTest method ifCacheWorks.
@Test
public void ifCacheWorks() {
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(series), 3);
Decimal firstTime = sma.getValue(4);
Decimal secondTime = sma.getValue(4);
assertEquals(firstTime, secondTime);
}
Aggregations