/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); assertEquals(c1, c2); // add a series OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); assertFalse(c1.equals(c2)); OHLCSeries s2 = new OHLCSeries("Series"); s2.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c2.addSeries(s2); assertTrue(c1.equals(c2)); // add an empty series c1.addSeries(new OHLCSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new OHLCSeries("Empty Series")); assertTrue(c1.equals(c2)); }
/** * Some checks for the {@link OHLCSeriesCollection#removeSeries(int)} * method. */ public void testRemoveSeries_int() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series 1"); OHLCSeries s2 = new OHLCSeries("Series 2"); OHLCSeries s3 = new OHLCSeries("Series 3"); OHLCSeries s4 = new OHLCSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(2); assertTrue(c1.getSeries(2).equals(s4)); c1.removeSeries(0); assertTrue(c1.getSeries(0).equals(s2)); assertEquals(2, c1.getSeriesCount()); }
/** * Some checks for the * {@link OHLCSeriesCollection#removeSeries(OHLCSeries)} method. */ public void testRemoveSeries() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series 1"); OHLCSeries s2 = new OHLCSeries("Series 2"); OHLCSeries s3 = new OHLCSeries("Series 3"); OHLCSeries s4 = new OHLCSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(s3); assertTrue(c1.getSeries(2).equals(s4)); c1.removeSeries(s1); assertTrue(c1.getSeries(0).equals(s2)); assertEquals(2, c1.getSeriesCount()); }
/** * A simple check for the removeAllSeries() method. */ public void testRemoveAllSeries() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); c1.addChangeListener(this); // there should be no change event when clearing an empty series this.lastEvent = null; c1.removeAllSeries(); assertNull(this.lastEvent); OHLCSeries s1 = new OHLCSeries("Series 1"); OHLCSeries s2 = new OHLCSeries("Series 2"); c1.addSeries(s1); c1.addSeries(s2); c1.removeAllSeries(); assertEquals(0, c1.getSeriesCount()); assertNotNull(this.lastEvent); this.lastEvent = null; // clean up }
/** * Simple test for the indexOf() method. */ public void testIndexOf() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2011), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2010), 2.0, 4.0, 1.0, 3.0); assertEquals(0, s1.indexOf(new Year(2006))); assertEquals(1, s1.indexOf(new Year(2010))); assertEquals(2, s1.indexOf(new Year(2011))); }
/** * Simple test for the remove() method. */ public void testRemove() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2011), 2.1, 4.1, 1.1, 3.1); s1.add(new Year(2010), 2.2, 4.2, 1.2, 3.2); assertEquals(3, s1.getItemCount()); s1.remove(new Year(2010)); assertEquals(new Year(2011), s1.getPeriod(1)); s1.remove(new Year(2006)); assertEquals(new Year(2011), s1.getPeriod(0)); }
/** * If you add a duplicate period, an exception should be thrown. */ public void testAdditionOfDuplicatePeriod() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0); boolean pass = false; try { s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0); } catch (SeriesException e) { pass = true; } assertTrue(pass); }
/** * A simple check that the maximumItemCount attribute is working. */ public void testSetMaximumItemCount() { OHLCSeries s1 = new OHLCSeries("s1"); assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount()); s1.setMaximumItemCount(2); assertEquals(2, s1.getMaximumItemCount()); s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1); s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2); s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3); assertEquals(new Year(2007), s1.getPeriod(0)); assertEquals(new Year(2008), s1.getPeriod(1)); }
/** * Check that the maximum item count can be applied retrospectively. */ public void testSetMaximumItemCount2() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1); s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2); s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3); s1.setMaximumItemCount(2); assertEquals(new Year(2007), s1.getPeriod(0)); assertEquals(new Year(2008), s1.getPeriod(1)); }
public static boolean updateSeries(OHLCSeriesCollection dataset, int series, List<Trade> trade) { OHLCSeries ohlcs = dataset.getSeries(series); try { addToSeries(ohlcs, trade); } catch(SeriesException e) { // overlap with dates return false; } return true; }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); assertEquals(c1, c2); // add a series OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); assertFalse(c1.equals(c2)); OHLCSeries s2 = new OHLCSeries("Series"); s2.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c2.addSeries(s2); assertTrue(c1.equals(c2)); // add an empty series c1.addSeries(new OHLCSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new OHLCSeries("Empty Series")); assertTrue(c1.equals(c2)); c1.setXPosition(TimePeriodAnchor.END); assertFalse(c1.equals(c2)); c2.setXPosition(TimePeriodAnchor.END); assertTrue(c1.equals(c2)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("S"); s1.add(new Year(2009), 1.0, 4.0, 0.5, 2.0); c1.addSeries(s1); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); OHLCSeries s2 = new OHLCSeries("S"); s2.add(new Year(2009), 1.0, 4.0, 0.5, 2.0); c2.addSeries(s2); assertTrue(c1.equals(c2)); int h1 = c1.hashCode(); int h2 = c2.hashCode(); assertEquals(h1, h2); }
/** * Some checks for the clear() method. */ public void testClear() { OHLCSeries s1 = new OHLCSeries("S1"); s1.addChangeListener(this); s1.clear(); assertNull(this.lastEvent); assertTrue(s1.isEmpty()); s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1); assertFalse(s1.isEmpty()); s1.clear(); assertNotNull(this.lastEvent); assertTrue(s1.isEmpty()); }
@Override public void addCandlestickChart(String chartTitle, String seriesTitle, Date date, double open, double high, double low, double close) { TimeChartDefinition definition = getOrCreateTimeChartDefinition(chartTitle); OHLCSeries series = definition.ohlcSeries.computeIfAbsent(seriesTitle, OHLCSeries::new); series.add(new Minute(date), open, high, low, close); }
public static OHLCSeries makeSeries(List<Trade> trade, Comparable<String> key) { OHLCSeries ohlcs = new OHLCSeries(key); addToSeries(ohlcs, trade); return ohlcs; }
private static void addToSeries(OHLCSeries ohlcs, List<Trade> trade) { // if (trade.isEmpty()) { // return; // } // int k = 0; // Day rtp = new Day(trade.get(k).getExecutionTimestamp()); //day time period // String rna = trade.get(k).getRoundedNotionalAmount1(); // //cycle through trade list looking for first readable rounded notional amount 1 // while (!(RNAExtractor.validRNA(rna)) && k < trade.size() - 1) { // k++; // rtp = new Day(trade.get(k).getExecutionTimestamp()); // rna = trade.get(k).getRoundedNotionalAmount1(); // } // //if they are all unreadable // if (k == trade.size() - 1) { // return; // } // double open = RNAExtractor.getDoubleRNA(rna); // double high = open; // double low = open; // double close = open; // for (int i = k; i < trade.size(); i++) { // Trade currentTrade = trade.get(i); // rna = currentTrade.getRoundedNotionalAmount1(); // if (RNAExtractor.validRNA(rna)) { // double price = RNAExtractor.getDoubleRNA(rna); // if(rtp.equals(new Day(currentTrade.getExecutionTimestamp()))) { //same time period // if (price > high) { // high = price; // } // if (price < low) { // low = price; // } // close = price; // } else { // ohlcs.add(rtp, open, high, low, close); // rtp = new Day(currentTrade.getExecutionTimestamp()); // open = price; // high = open; // low = open; // close = open; // } // } // } // ohlcs.add(rtp, open, high, low, close); //add last item in }