Search in sources :

Example 46 with Decimal

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));
    }
}
Also used : Decimal(org.ta4j.core.Decimal) Test(org.junit.Test)

Example 47 with Decimal

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));
}
Also used : Decimal(org.ta4j.core.Decimal) Test(org.junit.Test)

Example 48 with Decimal

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));
}
Also used : Decimal(org.ta4j.core.Decimal) Test(org.junit.Test)

Example 49 with Decimal

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);
    }
}
Also used : Decimal(org.ta4j.core.Decimal) Test(org.junit.Test)

Example 50 with Decimal

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);
}
Also used : Decimal(org.ta4j.core.Decimal) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

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