use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CashFlowTest method reallyLongCashFlow.
@Test
public void reallyLongCashFlow() {
int size = 1000000;
TimeSeries sampleTimeSeries = new MockTimeSeries(Collections.nCopies(size, new MockBar(10)));
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(size - 1, sampleTimeSeries));
CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
assertDecimalEquals(cashFlow.getValue(size - 1), 1);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CashFlowTest method cashFlowSize.
@Test
public void cashFlowSize() {
TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 2d, 3d, 4d, 5d);
CashFlow cashFlow = new CashFlow(sampleTimeSeries, new BaseTradingRecord());
assertEquals(5, cashFlow.getSize());
}
use of org.ta4j.core.mocks.MockTimeSeries 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);
}
use of org.ta4j.core.mocks.MockTimeSeries 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");
}
use of org.ta4j.core.mocks.MockTimeSeries 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);
}
Aggregations