private void plotTradeBubblesOnChart(ArrayList<Integer> toPlot, String p, int k, int j) { final Plot main_plot = (Plot)((CombinedDomainXYPlot)this.candlestickChart.getPlot()).getSubplots().get(0); final XYPlot plot = (XYPlot) main_plot; final TimeSeries series = new TimeSeries(p); ///* for(Integer i: toPlot) { switch(j) { case 0: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getOpen()); break; case 1: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getHigh()); break; case 2: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getLow()); break; case 3: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getClose()); break; } } /* for (int i = 0; i < defaultHighLowDataset.getSeriesCount(); i++) { series.add(new Minute(defaultHighLowDataset.getXDate(0, i)),plot[i]); } */ XYDataset dataSet = new TimeSeriesCollection(series); plot.setDataset(k, dataSet); XYItemRenderer ir = new XYShapeRenderer(); //ir.s plot.setRenderer(k, ir); }
private XYDataset createIndicatorPlot(String name, Double[] plot) { final TimeSeries series = new TimeSeries(name); ///* for (int i = 0; i < chartDatas.size(); i++) { series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),plot[i]); } /* for (int i = 0; i < defaultHighLowDataset.getSeriesCount(); i++) { series.add(new Minute(defaultHighLowDataset.getXDate(0, i)),plot[i]); } */ return new TimeSeriesCollection(series); }
/** * Runs a strategy over a time series and adds the value markers * corresponding to buy/sell signals to the plot. * @param series a time series * @param strategy a trading strategy * @param plot the plot */ private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) { // Running the strategy TimeSeriesManager seriesManager = new TimeSeriesManager(series); List<Trade> trades = seriesManager.run(strategy).getTrades(); // Adding markers to plot for (Trade trade : trades) { // Buy signal double buySignalTickTime = new Minute(Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond(); Marker buyMarker = new ValueMarker(buySignalTickTime); buyMarker.setPaint(Color.GREEN); buyMarker.setLabel("B"); plot.addDomainMarker(buyMarker); // Sell signal double sellSignalTickTime = new Minute(Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond(); Marker sellMarker = new ValueMarker(sellSignalTickTime); sellMarker.setPaint(Color.RED); sellMarker.setLabel("S"); plot.addDomainMarker(sellMarker); } }
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) { // Running the strategy TimeSeriesManager seriesManager = new TimeSeriesManager(series); List<Trade> trades = seriesManager.run(strategy).getTrades(); // Adding markers to plot for (Trade trade : trades) { // Buy signal double buySignalTickTime = new Minute( Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())) .getFirstMillisecond(); Marker buyMarker = new ValueMarker(buySignalTickTime); buyMarker.setPaint(Color.GREEN); buyMarker.setLabel("B"); plot.addDomainMarker(buyMarker); // Sell signal double sellSignalTickTime = new Minute( Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())) .getFirstMillisecond(); Marker sellMarker = new ValueMarker(sellSignalTickTime); sellMarker.setPaint(Color.RED); sellMarker.setLabel("S"); plot.addDomainMarker(sellMarker); } }
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithTimeZone() { Minute m = new Minute(59, 15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); assertEquals(-623289660000L, m.getFirstMillisecond(zone)); // try null calendar boolean pass = false; try { m.getFirstMillisecond((TimeZone) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithCalendar() { Minute m = new Minute(40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); assertEquals(955762800000L, m.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; try { m.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithTimeZone() { Minute m = new Minute(1, 2, 7, 7, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); assertEquals(-614962680001L, m.getLastMillisecond(zone)); // try null calendar boolean pass = false; try { m.getLastMillisecond((TimeZone) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithCalendar() { Minute m = new Minute(45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); assertEquals(987885959999L, m.getLastMillisecond(calendar)); // try null calendar boolean pass = false; try { m.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
private XYDataset createDataset() throws JDependException { TimeSeries scoreSeries = new TimeSeries("总分"); TimeSeries dSeries = new TimeSeries("抽象程度合理性"); TimeSeries balanceSeries = new TimeSeries("内聚性"); TimeSeries relationSeries = new TimeSeries("关系合理性"); AnalysisResult result; for (ExecuteResultSummry summary : this.results.keySet()) { result = this.results.get(summary); scoreSeries.add(new Minute(summary.getCreateDate()), result.getScore()); dSeries.add(new Minute(summary.getCreateDate()), result.getDistance()); balanceSeries.add(new Minute(summary.getCreateDate()), result.getBalance()); relationSeries.add(new Minute(summary.getCreateDate()), result.getRelationRationality()); } TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(scoreSeries); timeseriescollection.addSeries(dSeries); timeseriescollection.addSeries(balanceSeries); timeseriescollection.addSeries(relationSeries); return timeseriescollection; }
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithTimeZone() { Minute m = new Minute(59, 15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623289660000L, m.getFirstMillisecond(c)); // try null calendar boolean pass = false; try { m.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithCalendar() { Minute m = new Minute(40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(955766400000L, m.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; try { m.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithTimeZone() { Minute m = new Minute(1, 2, 7, 7, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-614962680001L, m.getLastMillisecond(c)); // try null calendar boolean pass = false; try { m.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithCalendar() { Minute m = new Minute(45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(987889559999L, m.getLastMillisecond(calendar)); // try null calendar boolean pass = false; try { m.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
private void plotSeperatePosition(HashMap<Integer,Double> toPlot) { final TimeSeries series = new TimeSeries("Position"); double curVal = 0.0; for(int i=0;i<chartDatas.size();i++) { if(toPlot.get(i)!=null) { curVal=toPlot.get(i); } series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),curVal); } plotSeperate(new TimeSeriesCollection(series),"Position"); }
/** * Builds a JFreeChart time series from a Ta4j time series and an indicator. * @param tickSeries the ta4j time series * @param indicator the indicator * @param name the name of the chart time series * @return the JFreeChart time series */ private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries, Indicator<Decimal> indicator, String name) { org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name); for (int i = 0; i < tickSeries.getTickCount(); i++) { Tick tick = tickSeries.getTick(i); chartTimeSeries.add(new Minute(Date.from(tick.getEndTime().toInstant())), indicator.getValue(i).toDouble()); } return chartTimeSeries; }
/** * Builds a JFreeChart time series from a Ta4j time series and an indicator. * @param tickSeries the ta4j time series * @param indicator the indicator * @param name the name of the chart time series * @return the JFreeChart time series */ private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries, Indicator<Decimal> indicator, String name) { org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name); for (int i = 0; i < tickSeries.getTickCount(); i++) { Tick tick = tickSeries.getTick(i); chartTimeSeries.add(new Minute(new Date(tick.getEndTime().toEpochSecond() * 1000)), indicator.getValue(i).toDouble()); } return chartTimeSeries; }
private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries, Indicator<Decimal> indicator, String name) { org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name); for (int i = 0; i < tickSeries.getTickCount(); i++) { Tick tick = tickSeries.getTick(i); chartTimeSeries.add(new Minute(Date.from(tick.getEndTime().toInstant())), indicator.getValue(i).toDouble()); } return chartTimeSeries; }
/** * Tests the equals method. */ public void testEquals() { final Day day1 = new Day(29, SerialDate.MARCH, 2002); final Hour hour1 = new Hour(15, day1); final Minute minute1 = new Minute(15, hour1); final Second second1 = new Second(34, minute1); final Millisecond milli1 = new Millisecond(999, second1); final Day day2 = new Day(29, SerialDate.MARCH, 2002); final Hour hour2 = new Hour(15, day2); final Minute minute2 = new Minute(15, hour2); final Second second2 = new Second(34, minute2); final Millisecond milli2 = new Millisecond(999, second2); assertTrue(milli1.equals(milli2)); }
/** * Tests the equals method. */ public void testEquals() { final Day day1 = new Day(29, SerialDate.MARCH, 2002); final Hour hour1 = new Hour(15, day1); final Minute minute1 = new Minute(15, hour1); final Day day2 = new Day(29, SerialDate.MARCH, 2002); final Hour hour2 = new Hour(15, day2); final Minute minute2 = new Minute(15, hour2); assertTrue(minute1.equals(minute2)); }
/** * In GMT, the 4.55pm on 21 Mar 2002 is java.util.Date(1016729700000L). * Use this to check the Minute constructor. */ public void testDateConstructor1() { final TimeZone zone = TimeZone.getTimeZone("GMT"); final Minute m1 = new Minute(new Date(1016729699999L), zone); final Minute m2 = new Minute(new Date(1016729700000L), zone); assertEquals(54, m1.getMinute()); assertEquals(1016729699999L, m1.getLastMillisecond(zone)); assertEquals(55, m2.getMinute()); assertEquals(1016729700000L, m2.getFirstMillisecond(zone)); }
/** * In Singapore, the 4.55pm on 21 Mar 2002 is java.util.Date(1,014,281,700,000L). * Use this to check the Minute constructor. */ public void testDateConstructor2() { final TimeZone zone = TimeZone.getTimeZone("Asia/Singapore"); final Minute m1 = new Minute(new Date(1016700899999L), zone); final Minute m2 = new Minute(new Date(1016700900000L), zone); assertEquals(54, m1.getMinute()); assertEquals(1016700899999L, m1.getLastMillisecond(zone)); assertEquals(55, m2.getMinute()); assertEquals(1016700900000L, m2.getFirstMillisecond(zone)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { final Minute m1 = new Minute(45, 5, 1, 2, 2003); final Minute m2 = new Minute(45, 5, 1, 2, 2003); assertTrue(m1.equals(m2)); final int h1 = m1.hashCode(); final int h2 = m2.hashCode(); assertEquals(h1, h2); }
/** * Tests the equals method. */ public void testEquals() { final Day day1 = new Day(29, SerialDate.MARCH, 2002); final Hour hour1 = new Hour(15, day1); final Minute minute1 = new Minute(15, hour1); final Second second1 = new Second(34, minute1); final Day day2 = new Day(29, SerialDate.MARCH, 2002); final Hour hour2 = new Hour(15, day2); final Minute minute2 = new Minute(15, hour2); final Second second2 = new Second(34, minute2); assertTrue(second1.equals(second2)); }
/** * Tests the equals method. */ public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Hour hour1 = new Hour(15, day1); Minute minute1 = new Minute(15, hour1); Second second1 = new Second(34, minute1); Millisecond milli1 = new Millisecond(999, second1); Day day2 = new Day(29, MonthConstants.MARCH, 2002); Hour hour2 = new Hour(15, day2); Minute minute2 = new Minute(15, hour2); Second second2 = new Second(34, minute2); Millisecond milli2 = new Millisecond(999, second2); assertTrue(milli1.equals(milli2)); }
/** * Tests the equals method. */ public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Hour hour1 = new Hour(15, day1); Minute minute1 = new Minute(15, hour1); Day day2 = new Day(29, MonthConstants.MARCH, 2002); Hour hour2 = new Hour(15, day2); Minute minute2 = new Minute(15, hour2); assertTrue(minute1.equals(minute2)); }
/** * In GMT, the 4.55pm on 21 Mar 2002 is java.util.Date(1016729700000L). * Use this to check the Minute constructor. */ public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Minute m1 = new Minute(new Date(1016729699999L), zone); Minute m2 = new Minute(new Date(1016729700000L), zone); assertEquals(54, m1.getMinute()); assertEquals(1016729699999L, m1.getLastMillisecond(zone)); assertEquals(55, m2.getMinute()); assertEquals(1016729700000L, m2.getFirstMillisecond(zone)); }
/** * In Singapore, the 4.55pm on 21 Mar 2002 is * java.util.Date(1,014,281,700,000L). Use this to check the Minute * constructor. */ public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Asia/Singapore"); Minute m1 = new Minute(new Date(1016700899999L), zone); Minute m2 = new Minute(new Date(1016700900000L), zone); assertEquals(54, m1.getMinute()); assertEquals(1016700899999L, m1.getLastMillisecond(zone)); assertEquals(55, m2.getMinute()); assertEquals(1016700900000L, m2.getFirstMillisecond(zone)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { Minute m1 = new Minute(45, 5, 1, 2, 2003); Minute m2 = new Minute(45, 5, 1, 2, 2003); assertTrue(m1.equals(m2)); int h1 = m1.hashCode(); int h2 = m2.hashCode(); assertEquals(h1, h2); }
/** * Some checks for the getFirstMillisecond() method. */ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); Minute m = new Minute(43, 15, 1, 4, 2006); assertEquals(1143902580000L, m.getFirstMillisecond()); Locale.setDefault(saved); }
/** * Some checks for the getLastMillisecond() method. */ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); Minute m = new Minute(1, 1, 1, 1, 1970); assertEquals(119999L, m.getLastMillisecond()); Locale.setDefault(saved); }
/** * Some checks for the getStart() method. */ public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0); cal.set(Calendar.MILLISECOND, 0); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); }
/** * Some checks for the getEnd() method. */ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59); cal.set(Calendar.MILLISECOND, 999); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); }
/** * Tests the equals method. */ public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Hour hour1 = new Hour(15, day1); Minute minute1 = new Minute(15, hour1); Second second1 = new Second(34, minute1); Day day2 = new Day(29, MonthConstants.MARCH, 2002); Hour hour2 = new Hour(15, day2); Minute minute2 = new Minute(15, hour2); Second second2 = new Second(34, minute2); assertTrue(second1.equals(second2)); }
private XYDataset createTimePeriodDataset() { if (sampleTimePeriodDataset == null) { TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); Day today = new Day(); TimePeriodValues series1 = new TimePeriodValues("First"); TimePeriodValues series2 = new TimePeriodValues("Second"); for (int i = 0; i < 24; i++) { Minute m0 = new Minute(0, new Hour(i, today)); Minute m1 = new Minute(15, new Hour(i, today)); Minute m2 = new Minute(30, new Hour(i, today)); Minute m3 = new Minute(45, new Hour(i, today)); Minute m4 = new Minute(0, new Hour(i + 1, today)); series1.add(new SimpleTimePeriod(m0.getStart(), m1.getStart()), Math.random()); series2.add(new SimpleTimePeriod(m1.getStart(), m2.getStart()), Math.random()); series1.add(new SimpleTimePeriod(m2.getStart(), m3.getStart()), Math.random()); series2.add(new SimpleTimePeriod(m3.getStart(), m4.getStart()), Math.random()); } dataset.addSeries(series1); dataset.addSeries(series2); sampleTimePeriodDataset = dataset; } return sampleTimePeriodDataset; }
/** * parse EEE MMM dd kk:mm:ss zzz yyyy to Minute * */ public static Minute parseMinute(String date){ SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss zzz yyyy"); Date time = df.parse(date,new ParsePosition(0)); return new Minute(time); }