/** * Creates a new second. * * @param second the second (0-59). * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Second(int second, int minute, int hour, int day, int month, int year) { this(second, new Minute(minute, hour, day, month, year)); }
/** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); }
/** * Constructs a new Second. * * @param second the second (0 to 24*60*60-1). * @param minute the minute (<code>null</code> not permitted). */ public Second(int second, Minute minute) { if (minute == null) { throw new IllegalArgumentException("Null 'minute' argument."); } this.day = minute.getDay(); this.hour = (byte) minute.getHourValue(); this.minute = (byte) minute.getMinute(); this.second = (byte) second; peg(Calendar.getInstance()); }
/** * Returns the minute preceding this one. * * @return The minute preceding this one. */ public RegularTimePeriod previous() { Minute result; if (this.minute != FIRST_MINUTE_IN_HOUR) { result = new Minute(this.minute - 1, getHour()); } else { Hour h = (Hour) getHour().previous(); if (h != null) { result = new Minute(LAST_MINUTE_IN_HOUR, h); } else { result = null; } } return result; }
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.getBar(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.getBar(trade.getExit().getIndex()).getEndTime().toInstant())) .getFirstMillisecond(); Marker sellMarker = new ValueMarker(sellSignalTickTime); sellMarker.setPaint(Color.RED); sellMarker.setLabel("S"); plot.addDomainMarker(sellMarker); } }
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());
/** * Returns the minute following this one. * * @return The minute following this one. */ @Override public RegularTimePeriod next() { Minute result; if (this.minute != LAST_MINUTE_IN_HOUR) { result = new Minute(this.minute + 1, getHour()); } else { // we are at the last minute in the hour... Hour nextHour = (Hour) getHour().next(); if (nextHour != null) { result = new Minute(FIRST_MINUTE_IN_HOUR, nextHour); } else { result = null; } } return result; }
/** * 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); } }
/** * Creates a new second. * * @param second the second (0-59). * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Second(int second, int minute, int hour, int day, int month, int year) { this(second, new Minute(minute, hour, day, month, year)); }
/** * Returns the minute preceding this one. * * @return The minute preceding this one. */ @Override public RegularTimePeriod previous() { Minute result; if (this.minute != FIRST_MINUTE_IN_HOUR) { result = new Minute(this.minute - 1, getHour()); } else { Hour h = (Hour) getHour().previous(); if (h != null) { result = new Minute(LAST_MINUTE_IN_HOUR, h); } else { result = null; } } return result; }
/** * Constructs a new Second. * * @param second the second (0 to 59). * @param minute the minute ({@code null} not permitted). */ public Second(int second, Minute minute) { Args.requireInRange(second, "second", Second.FIRST_SECOND_IN_MINUTE, Second.LAST_SECOND_IN_MINUTE); Args.nullNotPermitted(minute, "minute"); this.day = minute.getDay(); this.hour = (byte) minute.getHourValue(); this.minute = (byte) minute.getMinute(); this.second = (byte) second; peg(Calendar.getInstance()); }
/** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar ({@code null} not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); }
/** * Returns the minute. * * @return The minute (never {@code null}). */ public Minute getMinute() { return new Minute(this.minute, new Hour(this.hour, this.day)); }
/** * Returns the minute following this one. * * @return The minute following this one. */ public RegularTimePeriod next() { Minute result; if (this.minute != LAST_MINUTE_IN_HOUR) { result = new Minute(this.minute + 1, getHour()); } else { // we are at the last minute in the hour... Hour nextHour = (Hour) getHour().next(); if (nextHour != null) { result = new Minute(FIRST_MINUTE_IN_HOUR, nextHour); } else { result = null; } } return result; }
/** * Constructs a millisecond. * * @param millisecond the millisecond (0-999). * @param second the second. */ public Millisecond(int millisecond, Second second) { this.millisecond = millisecond; this.second = (byte) second.getSecond(); this.minute = (byte) second.getMinute().getMinute(); this.hour = (byte) second.getMinute().getHourValue(); this.day = second.getMinute().getDay(); peg(Calendar.getInstance()); }
/** * Returns the minute. * * @return The minute (never <code>null</code>). */ public Minute getMinute() { return new Minute(this.minute, new Hour(this.hour, this.day)); }
/** * Constructs a millisecond. * * @param millisecond the millisecond (0-999). * @param second the second. */ public Millisecond(int millisecond, Second second) { this.millisecond = millisecond; this.second = (byte) second.getSecond(); this.minute = (byte) second.getMinute().getMinute(); this.hour = (byte) second.getMinute().getHourValue(); this.day = second.getMinute().getDay(); peg(Calendar.getInstance()); }
int minute = Integer.parseInt(minstr); if ((minute >= 0) && (minute <= 59)) { result = new Minute(minute, new Hour(hour, day));