use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class LinearTransactionCostCriterionTest method externalData.
@Test
public void externalData() throws Exception {
TimeSeries xlsSeries = xls.getSeries();
TradingRecord xlsTradingRecord = xls.getTradingRecord();
double value;
value = getCriterion(1000d, 0.005, 0.2).calculate(xlsSeries, xlsTradingRecord);
assertEquals(xls.getFinalCriterionValue(1000d, 0.005, 0.2).doubleValue(), value, TATestsUtils.TA_OFFSET);
assertEquals(843.5492, value, TATestsUtils.TA_OFFSET);
value = getCriterion(1000d, 0.1, 1.0).calculate(xlsSeries, xlsTradingRecord);
assertEquals(xls.getFinalCriterionValue(1000d, 0.1, 1.0).doubleValue(), value, TATestsUtils.TA_OFFSET);
assertEquals(1122.4410, value, TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class CachedIndicatorTest method getValueOnResultsCalculatedFromRemovedBarsShouldReturnFirstRemainingResult.
@Test
public void getValueOnResultsCalculatedFromRemovedBarsShouldReturnFirstRemainingResult() {
TimeSeries timeSeries = new MockTimeSeries(1, 1, 1, 1, 1);
timeSeries.setMaximumBarCount(3);
assertEquals(2, timeSeries.getRemovedBarsCount());
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);
for (int i = 0; i < 5; i++) {
assertDecimalEquals(sma.getValue(i), 1);
}
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class CachedIndicatorTest method getValueWithOldResultsRemoval.
@Test
public void getValueWithOldResultsRemoval() {
double[] data = new double[20];
Arrays.fill(data, 1);
TimeSeries timeSeries = new MockTimeSeries(data);
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 10);
assertDecimalEquals(sma.getValue(5), 1);
assertDecimalEquals(sma.getValue(10), 1);
timeSeries.setMaximumBarCount(12);
assertDecimalEquals(sma.getValue(19), 1);
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class CachedIndicatorTest method strategyExecutionOnCachedIndicatorAndLimitedTimeSeries.
@Test
public void strategyExecutionOnCachedIndicatorAndLimitedTimeSeries() {
TimeSeries timeSeries = new MockTimeSeries(0, 1, 2, 3, 4, 5, 6, 7);
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);
// Theoretical values for SMA(2) cache: 0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5
timeSeries.setMaximumBarCount(6);
// Theoretical values for SMA(2) cache: null, null, 2, 2.5, 3.5, 4.5, 5.5, 6.5
Strategy strategy = new BaseStrategy(new OverIndicatorRule(sma, Decimal.THREE), new UnderIndicatorRule(sma, Decimal.THREE));
// Theoretical shouldEnter results: false, false, false, false, true, true, true, true
// Theoretical shouldExit results: false, false, true, true, false, false, false, false
// As we return the first bar/result found for the removed bars:
// -> Approximated values for ClosePrice cache: 2, 2, 2, 3, 4, 5, 6, 7
// -> Approximated values for SMA(2) cache: 2, 2, 2, 2.5, 3.5, 4.5, 5.5, 6.5
// Then enters/exits are also approximated:
// -> shouldEnter results: false, false, false, false, true, true, true, true
// -> shouldExit results: true, true, true, true, false, false, false, false
assertFalse(strategy.shouldEnter(0));
assertTrue(strategy.shouldExit(0));
assertFalse(strategy.shouldEnter(1));
assertTrue(strategy.shouldExit(1));
assertFalse(strategy.shouldEnter(2));
assertTrue(strategy.shouldExit(2));
assertFalse(strategy.shouldEnter(3));
assertTrue(strategy.shouldExit(3));
assertTrue(strategy.shouldEnter(4));
assertFalse(strategy.shouldExit(4));
assertTrue(strategy.shouldEnter(5));
assertFalse(strategy.shouldExit(5));
assertTrue(strategy.shouldEnter(6));
assertFalse(strategy.shouldExit(6));
assertTrue(strategy.shouldEnter(7));
assertFalse(strategy.shouldExit(7));
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class BollingerBandWidthIndicatorTest method setUp.
@Before
public void setUp() {
TimeSeries data = new MockTimeSeries(10, 12, 15, 14, 17, 20, 21, 20, 20, 19, 20, 17, 12, 12, 9, 8, 9, 10, 9, 10);
closePrice = new ClosePriceIndicator(data);
}
Aggregations