Search in sources :

Example 21 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class VersusBuyAndHoldCriterionTest method calculateOnlyWithLossTrades.

@Test
public void calculateOnlyWithLossTrades() {
    MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series));
    AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion());
    assertEquals(0.95 * 0.7 / 0.7, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 22 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class ATRIndicatorTest method testDummy.

@Test
public void testDummy() throws Exception {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(0, 12, 15, 8));
    bars.add(new MockBar(0, 8, 11, 6));
    bars.add(new MockBar(0, 15, 17, 14));
    bars.add(new MockBar(0, 15, 17, 14));
    bars.add(new MockBar(0, 0, 0, 2));
    Indicator<Decimal> indicator = getIndicator(new MockTimeSeries(bars), 3);
    assertEquals(7d, indicator.getValue(0).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(6d / 3 + (1 - 1d / 3) * indicator.getValue(0).doubleValue(), indicator.getValue(1).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(9d / 3 + (1 - 1d / 3) * indicator.getValue(1).doubleValue(), indicator.getValue(2).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(3d / 3 + (1 - 1d / 3) * indicator.getValue(2).doubleValue(), indicator.getValue(3).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(15d / 3 + (1 - 1d / 3) * indicator.getValue(3).doubleValue(), indicator.getValue(4).doubleValue(), TATestsUtils.TA_OFFSET);
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 23 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class AccelerationDecelerationIndicatorTest method setUp.

@Before
public void setUp() {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(0, 0, 16, 8));
    bars.add(new MockBar(0, 0, 12, 6));
    bars.add(new MockBar(0, 0, 18, 14));
    bars.add(new MockBar(0, 0, 10, 6));
    bars.add(new MockBar(0, 0, 8, 4));
    series = new MockTimeSeries(bars);
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) Bar(org.ta4j.core.Bar) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Before(org.junit.Before)

Example 24 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class CashFlowTest method cashFlowValueWithOnlyOneTradeAndAGapBefore.

@Test
public void cashFlowValueWithOnlyOneTradeAndAGapBefore() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 1d, 2d);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(1, sampleTimeSeries), Order.sellAt(2, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertDecimalEquals(cashFlow.getValue(0), 1);
    assertDecimalEquals(cashFlow.getValue(1), 1);
    assertDecimalEquals(cashFlow.getValue(2), 2);
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TradingRecord(org.ta4j.core.TradingRecord) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 25 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class CashFlowTest method cashFlowBuyWithOnlyOneTrade.

@Test
public void cashFlowBuyWithOnlyOneTrade() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 2d);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(1, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertDecimalEquals(cashFlow.getValue(0), 1);
    assertDecimalEquals(cashFlow.getValue(1), 2);
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TradingRecord(org.ta4j.core.TradingRecord) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Aggregations

MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)135 Test (org.junit.Test)90 MockBar (org.ta4j.core.mocks.MockBar)46 ArrayList (java.util.ArrayList)45 Before (org.junit.Before)45 Bar (org.ta4j.core.Bar)42 TimeSeries (org.ta4j.core.TimeSeries)29 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)25 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)17 TradingRecord (org.ta4j.core.TradingRecord)12 ZonedDateTime (java.time.ZonedDateTime)5 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)3 BaseStrategy (org.ta4j.core.BaseStrategy)3 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)3 Strategy (org.ta4j.core.Strategy)3 Decimal (org.ta4j.core.Decimal)2 TimeSeriesManager (org.ta4j.core.TimeSeriesManager)2 Trade (org.ta4j.core.Trade)2 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)2 FixedRule (org.ta4j.core.trading.rules.FixedRule)2