Program: 52693
Project: 52693
Buggy source:
/** 
 * Calculates the Simple Moving Average for the given range of days from the given startDate on. The method returns an object containing the X and Y Axes of the generated bollinger bands
 */
private void calculateBollingerBands(){
  if (security == null)   return;
  this.prices=security.getPricesIncludingLatest();
  int index;
  SecurityPrice startPrice=null;
  if (prices == null || prices.size() < calculatedMinimumDays)   return;
  if (startDate == null) {
    startPrice=this.getStartPrice();
    if (startPrice == null)     return;
    index=prices.indexOf(startPrice);
    if (index >= prices.size())     return;
  }
 else {
    startPrice=this.getStartPriceFromStartDate();
    if (startPrice == null)     return;
    index=prices.indexOf(startPrice);
    if (index >= prices.size())     return;
  }
  for (; index < prices.size(); index++) {
    if (index < BollingerBandsDays)     continue;
    LocalDate nextDate=prices.get(index).getTime();
    LocalDate isBefore=nextDate.plusDays(1);
    LocalDate isAfter=prices.get(index - BollingerBandsDays + 2).getTime();
    List<SecurityPrice> filteredPrices=this.getFilteredList(isBefore,isAfter);
    if (filteredPrices.size() < calculatedMinimumDays)     continue;
    double sum=filteredPrices.stream().mapToLong(SecurityPrice::getValue).sum();
    double QuotePriceAverage=sum / Values.Quote.divider() / filteredPrices.size();
    double tempQuotePriceVariance=0;
    for (int i=0; i < filteredPrices.size(); i++) {
      tempQuotePriceVariance+=((filteredPrices.get(i).getValue() / Values.Quote.divider()) - QuotePriceAverage) * ((filteredPrices.get(i).getValue() / Values.Quote.divider()) - QuotePriceAverage);
    }
    Double StandardDeviationBollingerBands=Math.sqrt(tempQuotePriceVariance / (filteredPrices.size() - 1)) * BollingerBandsFactor;
    Double valueBollingerBandsLowerBands=QuotePriceAverage;
    Double valueBollingerBandsUpperBands=QuotePriceAverage;
    valueBollingerBandsLowerBands-=StandardDeviationBollingerBands;
    valueBollingerBandsUpperBands+=StandardDeviationBollingerBands;
    valuesBollingerBandsLowerBands.add(valueBollingerBandsLowerBands);
    valuesBollingerBandsMiddleBands.add(QuotePriceAverage);
    valuesBollingerBandsUpperBands.add(valueBollingerBandsUpperBands);
    datesBollingerBands.add(prices.get(index).getTime());
  }
  LocalDate[] tmpDates=datesBollingerBands.toArray(new LocalDate[0]);
  Double[] tmpPricesLower=valuesBollingerBandsLowerBands.toArray(new Double[0]);
  Double[] tmpPricesMiddle=valuesBollingerBandsMiddleBands.toArray(new Double[0]);
  Double[] tmpPricesUpper=valuesBollingerBandsUpperBands.toArray(new Double[0]);
  this.BollingerBandsLowerBand.setDates(TimelineChart.toJavaUtilDate(tmpDates));
  this.BollingerBandsLowerBand.setValues(ArrayUtils.toPrimitive(tmpPricesLower));
  this.BollingerBandsMiddleBand.setDates(TimelineChart.toJavaUtilDate(tmpDates));
  this.BollingerBandsMiddleBand.setValues(ArrayUtils.toPrimitive(tmpPricesMiddle));
  this.BollingerBandsUpperBand.setDates(TimelineChart.toJavaUtilDate(tmpDates));
  this.BollingerBandsUpperBand.setValues(ArrayUtils.toPrimitive(tmpPricesUpper));
}

Fixed version (ground truth):
/** 
 * Calculates the Simple Moving Average for the given range of days from the given startDate on. The method returns an object containing the X and Y Axes of the generated bollinger bands
 */
private void calculateBollingerBands(){
  if (security == null)   return;
  this.prices=security.getPricesIncludingLatest();
  int index;
  SecurityPrice startPrice=null;
  if (prices == null || prices.size() < BollingerBandsDays + 3)   return;
  if (startDate == null) {
    startPrice=this.getStartPrice();
    if (startPrice == null)     return;
    index=prices.indexOf(startPrice);
    if (index >= prices.size())     return;
  }
 else {
    startPrice=this.getStartPriceFromStartDate();
    if (startPrice == null)     return;
    index=prices.indexOf(startPrice);
    if (index >= prices.size())     return;
  }
  for (; index < prices.size(); index++) {
    if (index < BollingerBandsDays)     continue;
    LocalDate nextDate=prices.get(index).getTime();
    LocalDate isBefore=nextDate.plusDays(1);
    LocalDate isAfter=prices.get(index - BollingerBandsDays + 2).getTime();
    List<SecurityPrice> filteredPrices=this.getFilteredList(isBefore,isAfter);
    if (filteredPrices.size() < calculatedMinimumDays)     continue;
    double sum=filteredPrices.stream().mapToLong(SecurityPrice::getValue).sum();
    double QuotePriceAverage=sum / Values.Quote.divider() / filteredPrices.size();
    double tempQuotePriceVariance=0;
    for (int i=0; i < filteredPrices.size(); i++) {
      tempQuotePriceVariance+=((filteredPrices.get(i).getValue() / Values.Quote.divider()) - QuotePriceAverage) * ((filteredPrices.get(i).getValue() / Values.Quote.divider()) - QuotePriceAverage);
    }
    Double StandardDeviationBollingerBands=Math.sqrt(tempQuotePriceVariance / (filteredPrices.size() - 1)) * BollingerBandsFactor;
    Double valueBollingerBandsLowerBands=QuotePriceAverage;
    Double valueBollingerBandsUpperBands=QuotePriceAverage;
    valueBollingerBandsLowerBands-=StandardDeviationBollingerBands;
    valueBollingerBandsUpperBands+=StandardDeviationBollingerBands;
    valuesBollingerBandsLowerBands.add(valueBollingerBandsLowerBands);
    valuesBollingerBandsMiddleBands.add(QuotePriceAverage);
    valuesBollingerBandsUpperBands.add(valueBollingerBandsUpperBands);
    datesBollingerBands.add(prices.get(index).getTime());
  }
  LocalDate[] tmpDates=datesBollingerBands.toArray(new LocalDate[0]);
  Double[] tmpPricesLower=valuesBollingerBandsLowerBands.toArray(new Double[0]);
  Double[] tmpPricesMiddle=valuesBollingerBandsMiddleBands.toArray(new Double[0]);
  Double[] tmpPricesUpper=valuesBollingerBandsUpperBands.toArray(new Double[0]);
  this.BollingerBandsLowerBand.setDates(TimelineChart.toJavaUtilDate(tmpDates));
  this.BollingerBandsLowerBand.setValues(ArrayUtils.toPrimitive(tmpPricesLower));
  this.BollingerBandsMiddleBand.setDates(TimelineChart.toJavaUtilDate(tmpDates));
  this.BollingerBandsMiddleBand.setValues(ArrayUtils.toPrimitive(tmpPricesMiddle));
  this.BollingerBandsUpperBand.setDates(TimelineChart.toJavaUtilDate(tmpDates));
  this.BollingerBandsUpperBand.setValues(ArrayUtils.toPrimitive(tmpPricesUpper));
}