use of org.ta4j.core.TimeSeries 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);
}
use of org.ta4j.core.TimeSeries 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");
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class TripleEMAIndicatorTest method setUp.
@Before
public void setUp() {
TimeSeries data = new MockTimeSeries(0.73, 0.72, 0.86, 0.72, 0.62, 0.76, 0.84, 0.69, 0.65, 0.71, 0.53, 0.73, 0.77, 0.67, 0.68);
closePrice = new ClosePriceIndicator(data);
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class WMAIndicatorTest method wmaUsingTimeFrame9UsingClosePrice.
@Test
public void wmaUsingTimeFrame9UsingClosePrice() {
// Example from http://traders.com/Documentation/FEEDbk_docs/2010/12/TradingIndexesWithHullMA.xls
TimeSeries data = new MockTimeSeries(84.53, 87.39, 84.55, 82.83, 82.58, 83.74, 83.33, 84.57, 86.98, 87.10, 83.11, 83.60, 83.66, 82.76, 79.22, 79.03, 78.18, 77.42, 74.65, 77.48, 76.87);
WMAIndicator wma = new WMAIndicator(new ClosePriceIndicator(data), 9);
assertDecimalEquals(wma.getValue(8), 84.4958);
assertDecimalEquals(wma.getValue(9), 85.0158);
assertDecimalEquals(wma.getValue(10), 84.6807);
assertDecimalEquals(wma.getValue(11), 84.5387);
assertDecimalEquals(wma.getValue(12), 84.4298);
assertDecimalEquals(wma.getValue(13), 84.1224);
assertDecimalEquals(wma.getValue(14), 83.1031);
assertDecimalEquals(wma.getValue(15), 82.1462);
assertDecimalEquals(wma.getValue(16), 81.1149);
assertDecimalEquals(wma.getValue(17), 80.0736);
assertDecimalEquals(wma.getValue(18), 78.6907);
assertDecimalEquals(wma.getValue(19), 78.1504);
assertDecimalEquals(wma.getValue(20), 77.6133);
}
use of org.ta4j.core.TimeSeries in project ta4j by ta4j.
the class CoppockCurveIndicatorTest method coppockCurveWithRoc14Roc11Wma10.
@Test
public void coppockCurveWithRoc14Roc11Wma10() {
// Example from http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:coppock_curve
TimeSeries data = new MockTimeSeries(872.81, 919.14, 919.32, 987.48, 1020.62, 1057.08, 1036.19, 1095.63, 1115.1, 1073.87, 1104.49, 1169.43, 1186.69, 1089.41, 1030.71, 1101.6, 1049.33, 1141.2, 1183.26, 1180.55, 1257.64, 1286.12, 1327.22, 1325.83, 1363.61, 1345.2, 1320.64, 1292.28, 1218.89, 1131.42, 1253.3, 1246.96, 1257.6, 1312.41, 1365.68, 1408.47, 1397.91, 1310.33, 1362.16, 1379.32);
CoppockCurveIndicator cc = new CoppockCurveIndicator(new ClosePriceIndicator(data), 14, 11, 10);
assertDecimalEquals(cc.getValue(31), 23.8929);
assertDecimalEquals(cc.getValue(32), 19.3187);
assertDecimalEquals(cc.getValue(33), 16.3505);
assertDecimalEquals(cc.getValue(34), 14.12);
assertDecimalEquals(cc.getValue(35), 12.782);
assertDecimalEquals(cc.getValue(36), 11.3924);
assertDecimalEquals(cc.getValue(37), 8.3662);
assertDecimalEquals(cc.getValue(38), 7.4532);
assertDecimalEquals(cc.getValue(39), 8.79);
}
Aggregations