Search in sources :

Example 11 with BaseTradingRecord

use of org.ta4j.core.BaseTradingRecord in project ta4j by ta4j.

the class CashFlowTest method cashFlowValueWithOnlyOneTradeAndAGapAfter.

@Test
public void cashFlowValueWithOnlyOneTradeAndAGapAfter() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 2d, 2d);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(1, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertEquals(3, cashFlow.getSize());
    assertDecimalEquals(cashFlow.getValue(0), 1);
    assertDecimalEquals(cashFlow.getValue(1), 2);
    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 12 with BaseTradingRecord

use of org.ta4j.core.BaseTradingRecord in project ta4j by ta4j.

the class CashFlowTest method cashFlowSell.

@Test
public void cashFlowSell() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(1, 2, 4, 8, 16, 32);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.sellAt(2, sampleTimeSeries), Order.buyAt(3, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertDecimalEquals(cashFlow.getValue(0), 1);
    assertDecimalEquals(cashFlow.getValue(1), 1);
    assertDecimalEquals(cashFlow.getValue(2), 1);
    assertDecimalEquals(cashFlow.getValue(3), "0.5");
    assertDecimalEquals(cashFlow.getValue(4), "0.5");
    assertDecimalEquals(cashFlow.getValue(5), "0.5");
}
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 13 with BaseTradingRecord

use of org.ta4j.core.BaseTradingRecord in project ta4j by ta4j.

the class CashFlowTest method cashFlowValueWithTwoTradesAndLongTimeWithoutOrders.

@Test
public void cashFlowValueWithTwoTradesAndLongTimeWithoutOrders() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 2d, 4d, 8d, 16d, 32d);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(1, sampleTimeSeries), Order.sellAt(2, sampleTimeSeries), Order.buyAt(4, sampleTimeSeries), Order.sellAt(5, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertDecimalEquals(cashFlow.getValue(0), 1);
    assertDecimalEquals(cashFlow.getValue(1), 1);
    assertDecimalEquals(cashFlow.getValue(2), 2);
    assertDecimalEquals(cashFlow.getValue(3), 2);
    assertDecimalEquals(cashFlow.getValue(4), 2);
    assertDecimalEquals(cashFlow.getValue(5), 4);
}
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 14 with BaseTradingRecord

use of org.ta4j.core.BaseTradingRecord in project ta4j by ta4j.

the class CashFlowTest method cashFlowWithSellAndBuyOrders.

@Test
public void cashFlowWithSellAndBuyOrders() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(2, 1, 3, 5, 6, 3, 20);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(1, sampleTimeSeries), Order.buyAt(3, sampleTimeSeries), Order.sellAt(4, sampleTimeSeries), Order.sellAt(5, sampleTimeSeries), Order.buyAt(6, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertDecimalEquals(cashFlow.getValue(0), 1);
    assertDecimalEquals(cashFlow.getValue(1), "0.5");
    assertDecimalEquals(cashFlow.getValue(2), "0.5");
    assertDecimalEquals(cashFlow.getValue(3), "0.5");
    assertDecimalEquals(cashFlow.getValue(4), "0.6");
    assertDecimalEquals(cashFlow.getValue(5), "0.6");
    assertDecimalEquals(cashFlow.getValue(6), "0.09");
}
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 15 with BaseTradingRecord

use of org.ta4j.core.BaseTradingRecord in project ta4j by ta4j.

the class NumberOfBarsCriterionTest method calculateWithNoTrades.

@Test
public void calculateWithNoTrades() {
    MockTimeSeries series = new MockTimeSeries(100, 105, 110, 100, 95, 105);
    AnalysisCriterion numberOfBars = new NumberOfBarsCriterion();
    assertEquals(0, (int) numberOfBars.calculate(series, new BaseTradingRecord()));
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) AnalysisCriterion(org.ta4j.core.AnalysisCriterion) Test(org.junit.Test)

Aggregations

BaseTradingRecord (org.ta4j.core.BaseTradingRecord)17 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)17 Test (org.junit.Test)15 TradingRecord (org.ta4j.core.TradingRecord)12 TimeSeries (org.ta4j.core.TimeSeries)11 Before (org.junit.Before)2 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)2 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)2 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)2 MockBar (org.ta4j.core.mocks.MockBar)1