@Test public void upscaledTo10DayBarsNotOnlyFinalBars() { final DurationBarAggregator barAggregator = new DurationBarAggregator(Duration.ofDays(10), false); final List<Bar> bars = barAggregator.aggregate(getOneDayBars()); assertEquals(2, bars.size()); }
@Override public List<Bar> aggregate(List<Bar> bars) { final List<Bar> aggregated = new ArrayList<>(); if (bars.isEmpty()) { return aggregated; } final Duration actualDur = bars.iterator().next().getTimePeriod(); final boolean isMultiplication = timePeriod.getSeconds() % actualDur.getSeconds() == 0; if (!isMultiplication) { throw new IllegalArgumentException( "Cannot aggregate bars: the new timePeriod must be a multiplication of the actual timePeriod."); } int i = 0; final Num zero = bars.iterator().next().getOpenPrice().numOf(0); while (i < bars.size()) { Bar bar = bars.get(i); final ZonedDateTime beginTime = bar.getBeginTime(); final Num open = bar.getOpenPrice(); Num high = bar.getHighPrice(); Num low = bar.getLowPrice(); Num close = null; Num volume = zero; Num amount = zero; Duration sumDur = Duration.ZERO; while (sumDur.compareTo(timePeriod) < 0) { if (i < bars.size()) { bar = bars.get(i); if (high == null || bar.getHighPrice().isGreaterThan(high)) { high = bar.getHighPrice(); } if (low == null || bar.getLowPrice().isLessThan(low)) { low = bar.getLowPrice(); } close = bar.getClosePrice(); volume = volume.plus(bar.getVolume()); amount = amount.plus(bar.getAmount()); } sumDur = sumDur.plus(actualDur); i++; } if (!onlyFinalBars || i <= bars.size()) { final Bar aggregatedBar = new BaseBar(timePeriod, beginTime.plus(timePeriod), open, high, low, close, volume, amount); aggregated.add(aggregatedBar); } } return aggregated; }
DurationBarAggregator implements BarAggregator { @Override public List<Bar> aggregate(List<Bar> bars) { final List<Bar> aggregated = new ArrayList<>(); if (bars.isEmpty()) { return aggregated; } final Duration actualDur = bars.iterator().next().getTimePeriod(); final boolean isMultiplication = timePeriod.getSeconds() % actualDur.getSeconds() == 0; if (!isMultiplication) { throw new IllegalArgumentException( "Cannot aggregate bars: the new timePeriod must be a multiplication of the actual timePeriod."); } int i = 0; final Num zero = bars.iterator().next().getOpenPrice().numOf(0); while (i < bars.size()) { Bar bar = bars.get(i); final ZonedDateTime beginTime = bar.getBeginTime(); final Num open = bar.getOpenPrice(); Num high = bar.getHighPrice(); Num low = bar.getLowPrice(); Num close = null; Num volume = zero; Num amount = zero; Duration sumDur = Duration.ZERO; while (sumDur.compareTo(timePeriod) < 0) { if (i < bars.size()) { bar = bars.get(i); if (high == null || bar.getHighPrice().isGreaterThan(high)) { high = bar.getHighPrice(); } if (low == null || bar.getLowPrice().isLessThan(low)) { low = bar.getLowPrice(); } close = bar.getClosePrice(); volume = volume.plus(bar.getVolume()); amount = amount.plus(bar.getAmount()); } sumDur = sumDur.plus(actualDur); i++; } if (!onlyFinalBars || i <= bars.size()) { final Bar aggregatedBar = new BaseBar(timePeriod, beginTime.plus(timePeriod), open, high, low, close, volume, amount); aggregated.add(aggregatedBar); } } return aggregated; } }
DurationBarAggregator implements BarAggregator { @Override public List<Bar> aggregate(List<Bar> bars) { final List<Bar> aggregated = new ArrayList<>(); if (bars.isEmpty()) { return aggregated; } final Duration actualDur = bars.iterator().next().getTimePeriod(); final boolean isMultiplication = timePeriod.getSeconds() % actualDur.getSeconds() == 0; if (!isMultiplication) { throw new IllegalArgumentException( "Cannot aggregate bars: the new timePeriod must be a multiplication of the actual timePeriod."); } int i = 0; final Num zero = bars.iterator().next().getOpenPrice().numOf(0); while (i < bars.size()) { Bar bar = bars.get(i); final ZonedDateTime beginTime = bar.getBeginTime(); final Num open = bar.getOpenPrice(); Num high = bar.getHighPrice(); Num low = bar.getLowPrice(); Num close = null; Num volume = zero; Num amount = zero; Duration sumDur = Duration.ZERO; while (sumDur.compareTo(timePeriod) < 0) { if (i < bars.size()) { bar = bars.get(i); if (high == null || bar.getHighPrice().isGreaterThan(high)) { high = bar.getHighPrice(); } if (low == null || bar.getLowPrice().isLessThan(low)) { low = bar.getLowPrice(); } close = bar.getClosePrice(); volume = volume.plus(bar.getVolume()); amount = amount.plus(bar.getAmount()); } sumDur = sumDur.plus(actualDur); i++; } if (!onlyFinalBars || i <= bars.size()) { final Bar aggregatedBar = new BaseBar(timePeriod, beginTime.plus(timePeriod), open, high, low, close, volume, amount); aggregated.add(aggregatedBar); } } return aggregated; } DurationBarAggregator(Duration timePeriod);  DurationBarAggregator(Duration timePeriod, boolean onlyFinalBars); }
DurationBarAggregator implements BarAggregator { @Override public List<Bar> aggregate(List<Bar> bars) { final List<Bar> aggregated = new ArrayList<>(); if (bars.isEmpty()) { return aggregated; } final Duration actualDur = bars.iterator().next().getTimePeriod(); final boolean isMultiplication = timePeriod.getSeconds() % actualDur.getSeconds() == 0; if (!isMultiplication) { throw new IllegalArgumentException( "Cannot aggregate bars: the new timePeriod must be a multiplication of the actual timePeriod."); } int i = 0; final Num zero = bars.iterator().next().getOpenPrice().numOf(0); while (i < bars.size()) { Bar bar = bars.get(i); final ZonedDateTime beginTime = bar.getBeginTime(); final Num open = bar.getOpenPrice(); Num high = bar.getHighPrice(); Num low = bar.getLowPrice(); Num close = null; Num volume = zero; Num amount = zero; Duration sumDur = Duration.ZERO; while (sumDur.compareTo(timePeriod) < 0) { if (i < bars.size()) { bar = bars.get(i); if (high == null || bar.getHighPrice().isGreaterThan(high)) { high = bar.getHighPrice(); } if (low == null || bar.getLowPrice().isLessThan(low)) { low = bar.getLowPrice(); } close = bar.getClosePrice(); volume = volume.plus(bar.getVolume()); amount = amount.plus(bar.getAmount()); } sumDur = sumDur.plus(actualDur); i++; } if (!onlyFinalBars || i <= bars.size()) { final Bar aggregatedBar = new BaseBar(timePeriod, beginTime.plus(timePeriod), open, high, low, close, volume, amount); aggregated.add(aggregatedBar); } } return aggregated; } DurationBarAggregator(Duration timePeriod);  DurationBarAggregator(Duration timePeriod, boolean onlyFinalBars); @Override List<Bar> aggregate(List<Bar> bars); }
DurationBarAggregator implements BarAggregator { @Override public List<Bar> aggregate(List<Bar> bars) { final List<Bar> aggregated = new ArrayList<>(); if (bars.isEmpty()) { return aggregated; } final Duration actualDur = bars.iterator().next().getTimePeriod(); final boolean isMultiplication = timePeriod.getSeconds() % actualDur.getSeconds() == 0; if (!isMultiplication) { throw new IllegalArgumentException( "Cannot aggregate bars: the new timePeriod must be a multiplication of the actual timePeriod."); } int i = 0; final Num zero = bars.iterator().next().getOpenPrice().numOf(0); while (i < bars.size()) { Bar bar = bars.get(i); final ZonedDateTime beginTime = bar.getBeginTime(); final Num open = bar.getOpenPrice(); Num high = bar.getHighPrice(); Num low = bar.getLowPrice(); Num close = null; Num volume = zero; Num amount = zero; Duration sumDur = Duration.ZERO; while (sumDur.compareTo(timePeriod) < 0) { if (i < bars.size()) { bar = bars.get(i); if (high == null || bar.getHighPrice().isGreaterThan(high)) { high = bar.getHighPrice(); } if (low == null || bar.getLowPrice().isLessThan(low)) { low = bar.getLowPrice(); } close = bar.getClosePrice(); volume = volume.plus(bar.getVolume()); amount = amount.plus(bar.getAmount()); } sumDur = sumDur.plus(actualDur); i++; } if (!onlyFinalBars || i <= bars.size()) { final Bar aggregatedBar = new BaseBar(timePeriod, beginTime.plus(timePeriod), open, high, low, close, volume, amount); aggregated.add(aggregatedBar); } } return aggregated; } DurationBarAggregator(Duration timePeriod);  DurationBarAggregator(Duration timePeriod, boolean onlyFinalBars); @Override List<Bar> aggregate(List<Bar> bars);  }