use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class PPOIndicatorTest method setUp.
@Before
public void setUp() {
TimeSeries series = new MockTimeSeries(22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, 22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82, 23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 21.40, 20.17);
closePriceIndicator = new ClosePriceIndicator(series);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class ParabolicSarIndicatorTest method startUpAndDownTrendTest.
@Test
public void startUpAndDownTrendTest() {
List<Bar> bars = new ArrayList<Bar>();
bars.add(new MockBar(0, 75.1, 74.06, 75.11));
bars.add(new MockBar(0, 75.9, 76.030000, 74.640000));
bars.add(new MockBar(0, 75.24, 76.269900, 75.060000));
bars.add(new MockBar(0, 75.17, 75.280000, 74.500000));
bars.add(new MockBar(0, 74.6, 75.310000, 74.540000));
bars.add(new MockBar(0, 74.1, 75.467000, 74.010000));
bars.add(new MockBar(0, 73.740000, 74.700000, 73.546000));
bars.add(new MockBar(0, 73.390000, 73.830000, 72.720000));
bars.add(new MockBar(0, 73.25, 73.890000, 72.86));
bars.add(new MockBar(0, 74.36, 74.410000, 73, 26));
bars.add(new MockBar(0, 76.510000, 76.830000, 74.820000));
bars.add(new MockBar(0, 75.590000, 76.850000, 74.540000));
bars.add(new MockBar(0, 75.910000, 76.960000, 75.510000));
bars.add(new MockBar(0, 74.610000, 77.070000, 74.560000));
bars.add(new MockBar(0, 75.330000, 75.530000, 74.010000));
bars.add(new MockBar(0, 75.010000, 75.500000, 74.510000));
bars.add(new MockBar(0, 75.620000, 76.210000, 75.250000));
bars.add(new MockBar(0, 76.040000, 76.460000, 75.092800));
bars.add(new MockBar(0, 76.450000, 76.450000, 75.435000));
bars.add(new MockBar(0, 76.260000, 76.470000, 75.840000));
bars.add(new MockBar(0, 76.850000, 77.000000, 76.190000));
ParabolicSarIndicator sar = new ParabolicSarIndicator(new MockTimeSeries(bars));
assertEquals(sar.getValue(0).toString(), "NaN");
assertDecimalEquals(sar.getValue(1), 74.640000000000000568434188608080);
// start with up trend
assertDecimalEquals(sar.getValue(2), 74.640000000000000568434188608080);
// switch to downtrend
assertDecimalEquals(sar.getValue(3), 76.269900000000006912159733474255);
// hold trend...
assertDecimalEquals(sar.getValue(4), 76.234502000000006773916538804770);
assertDecimalEquals(sar.getValue(5), 76.200611960000006763493729522452);
assertDecimalEquals(sar.getValue(6), 76.112987481600006697590288240463);
assertDecimalEquals(sar.getValue(7), 75.958968232704006684543855953962);
assertDecimalEquals(sar.getValue(8), 75.699850774087686058830877300352);
// switch to up trend
assertDecimalEquals(sar.getValue(9), 75.461462712160671083174936939031);
// hold trend
assertDecimalEquals(sar.getValue(10), 72.719999999999998863131622783840);
assertDecimalEquals(sar.getValue(11), 72.802199999999998851762939011678);
assertDecimalEquals(sar.getValue(12), 72.964111999999998670318746007979);
assertDecimalEquals(sar.getValue(13), 73.203865279999998374933056766167);
assertDecimalEquals(sar.getValue(14), 73.513156057599997959241591161117);
assertDecimalEquals(sar.getValue(15), 73.797703572991997576805442804471);
assertDecimalEquals(sar.getValue(16), 74.059487287152637224964186316356);
assertDecimalEquals(sar.getValue(17), 74.300328304180425701270230347291);
assertDecimalEquals(sar.getValue(18), 74.521902039845991099471790855751);
assertDecimalEquals(sar.getValue(19), 74.725749876658311265817226523534);
assertDecimalEquals(sar.getValue(20), 74.913289886525645818855027337894);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class BollingerBandsLowerIndicatorTest method setUp.
@Before
public void setUp() {
TimeSeries data = new MockTimeSeries(1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2);
timeFrame = 3;
closePrice = new ClosePriceIndicator(data);
sma = new SMAIndicator(closePrice, timeFrame);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class RewardRiskRatioCriterionTest method rewardRiskRatioCriterionWithNoTrades.
@Test
public void rewardRiskRatioCriterionWithNoTrades() {
MockTimeSeries series = new MockTimeSeries(1, 2, 3, 6, 8, 20, 3);
assertTrue(Double.isInfinite(rrc.calculate(series, new BaseTradingRecord())));
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class RewardRiskRatioCriterionTest method rewardRiskRatioCriterion.
@Test
public void rewardRiskRatioCriterion() {
MockTimeSeries series = new MockTimeSeries(100, 105, 95, 100, 90, 95, 80, 120);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(4, series), Order.buyAt(5, series), Order.sellAt(7, series));
double totalProfit = (105d / 100) * (90d / 95d) * (120d / 95);
double peak = (105d / 100) * (100d / 95);
double low = (105d / 100) * (90d / 95) * (80d / 95);
assertEquals(totalProfit / ((peak - low) / peak), rrc.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Aggregations