private void calculateRegressionLine(int startIndex, int endIndex) {
        // First pass: compute xBar and yBar
        Decimal sumX = Decimal.ZERO;
        Decimal sumY = Decimal.ZERO;
        for (int i = startIndex; i <= endIndex; i++) {
            sumX = sumX.plus(Decimal.valueOf(i));
            sumY = sumY.plus(indicator.getValue(i));
        }
        Decimal nbObservations = Decimal.valueOf(endIndex - startIndex + 1);
        Decimal xBar = sumX.dividedBy(nbObservations);
        Decimal yBar = sumY.dividedBy(nbObservations);
        
        // Second pass: compute slope and intercept
        Decimal xxBar = Decimal.ZERO;
        Decimal xyBar = Decimal.ZERO;
        for (int i = startIndex; i <= endIndex; i++) {
            Decimal dX = Decimal.valueOf(i).minus(xBar);
            Decimal dY = indicator.getValue(i).minus(yBar);
            xxBar = xxBar.plus(dX.multipliedBy(dX));
            xyBar = xyBar.plus(dX.multipliedBy(dY));
        }
        
        slope = xyBar.dividedBy(xxBar);
        intercept = yBar.minus(slope.multipliedBy(xBar));
    }
private void calculateRegressionLine(int startIndex, int endIndex) {
        
        Decimal sumX = Decimal.ZERO;
        Decimal sumY = Decimal.ZERO;
        for (int i = startIndex; i <= endIndex; i++) {
            sumX = sumX.plus(Decimal.valueOf(i));
            sumY = sumY.plus(indicator.getValue(i));
        }
        Decimal nbObservations = Decimal.valueOf(endIndex - startIndex + 1);
        Decimal xBar = sumX.dividedBy(nbObservations);
        Decimal yBar = sumY.dividedBy(nbObservations);
        
        
        Decimal xxBar = Decimal.ZERO;
        Decimal xyBar = Decimal.ZERO;
        for (int i = startIndex; i <= endIndex; i++) {
            Decimal dX = Decimal.valueOf(i).minus(xBar);
            Decimal dY = indicator.getValue(i).minus(yBar);
            xxBar = xxBar.plus(dX.multipliedBy(dX));
            xyBar = xyBar.plus(dX.multipliedBy(dY));
        }
        
        slope = xyBar.dividedBy(xxBar);
        intercept = yBar.minus(slope.multipliedBy(xBar));
    }
private void calculateRegressionLine ( int startIndex , int endIndex ) { // First pass: compute xBar and yBar Decimal sumX = Decimal . ZERO ; Decimal sumY = Decimal . ZERO ; for ( int i = startIndex ; i <= endIndex ; i ++ ) { sumX = sumX . plus ( Decimal . valueOf ( i ) ) ; sumY = sumY . plus ( indicator . getValue ( i ) ) ; } Decimal nbObservations = Decimal . valueOf ( endIndex - startIndex + 1 ) ; Decimal xBar = sumX . dividedBy ( nbObservations ) ; Decimal yBar = sumY . dividedBy ( nbObservations ) ; // Second pass: compute slope and intercept Decimal xxBar = Decimal . ZERO ; Decimal xyBar = Decimal . ZERO ; for ( int i = startIndex ; i <= endIndex ; i ++ ) { Decimal dX = Decimal . valueOf ( i ) . minus ( xBar ) ; Decimal dY = indicator . getValue ( i ) . minus ( yBar ) ; xxBar = xxBar . plus ( dX . multipliedBy ( dX ) ) ; xyBar = xyBar . plus ( dX . multipliedBy ( dY ) ) ; } slope = xyBar . dividedBy ( xxBar ) ; intercept = yBar . minus ( slope . multipliedBy ( xBar ) ) ; }
Calculates the regression line.
@param startIndex the start index (inclusive) in the time series
@param endIndex the end index (inclusive) in the time series
Calculates the regression line .