public static BarSeries convertBarSeries(BarSeries barSeries, Num num) {
        List<Bar> bars = barSeries.getBarData();
        if (bars == null || bars.isEmpty())
            return barSeries;
        List<Bar> convertedBars = new ArrayList<>();
        for (int i = barSeries.getBeginIndex(); i <= barSeries.getEndIndex(); i++) {
            Bar bar = bars.get(i);
            Function<Number, Num> conversionFunction = num.function();
            Bar convertedBar = new BaseBarConvertibleBuilder<>(conversionFunction::apply)
                    .timePeriod(bar.getTimePeriod())
                    .endTime(bar.getEndTime())
                    .openPrice(bar.getOpenPrice().getDelegate())
                    .highPrice(bar.getHighPrice().getDelegate())
                    .lowPrice(bar.getLowPrice().getDelegate())
                    .closePrice(bar.getClosePrice().getDelegate())
                    .volume(bar.getVolume().getDelegate())
                    .amount(bar.getAmount().getDelegate())
                    .trades(bar.getTrades())
                    .build();
            convertedBars.add(convertedBar);
        }
        BarSeries convertedBarSeries = new BaseBarSeries(barSeries.getName(), convertedBars, num);
        if (barSeries.getMaximumBarCount() > 0) {
            convertedBarSeries.setMaximumBarCount(barSeries.getMaximumBarCount());
        }

        return convertedBarSeries;
    }
@Test
    public void convertBarSeriesTest() {

        final Function<Number, Num> decimalNumFunction = DecimalNum::valueOf;
        final Num decimalNum = DecimalNum.ZERO;
        final Num doubleNum = DoubleNum.ZERO;
        final Num nanNum = NaN.NaN;

        final List<Bar> bars = new ArrayList<>();
        time = ZonedDateTime.of(2019, 6, 1, 1, 1, 0, 0, ZoneId.systemDefault());
        bars.add(new MockBar(time, 1d, 2d, 3d, 4d, 5d, 0d, 7, decimalNumFunction));
        bars.add(new MockBar(time.plusDays(1), 1d, 1d, 1d, 1d, 1d, 1d, 1, decimalNumFunction));
        bars.add(new MockBar(time.plusDays(2), 2d, 2d, 2d, 2d, 2d, 2d, 2, decimalNumFunction));

        final BarSeries decimalBarSeries = new BaseBarSeriesBuilder().withBars(bars)
                .withMaxBarCount(100)
                .withNumTypeOf(DecimalNum.class)
                .withName("useDecimalNum")
                .build();

        // convert barSeries with DecimalNum to barSeries with DoubleNum
        final BarSeries decimalToDoubleSeries = BarSeriesUtils.convertBarSeries(decimalBarSeries, doubleNum);

        // convert barSeries with DoubleNum to barSeries with DecimalNum
        final BarSeries doubleToDecimalSeries = BarSeriesUtils.convertBarSeries(decimalToDoubleSeries, decimalNum);

        // convert barSeries with DoubleNum to barSeries with NaNNum
        final BarSeries doubleToNaNSeries = BarSeriesUtils.convertBarSeries(decimalToDoubleSeries, nanNum);

        assertEquals(decimalBarSeries.getFirstBar().getClosePrice().getClass(), DecimalNum.class);
        assertEquals(decimalToDoubleSeries.getFirstBar().getClosePrice().getClass(), DoubleNum.class);
        assertEquals(doubleToDecimalSeries.getFirstBar().getClosePrice().getClass(), DecimalNum.class);
        assertEquals(doubleToNaNSeries.getFirstBar().getClosePrice().getClass(), NaN.class);
    }