Example usage for org.apache.commons.math.stat.descriptive.moment Variance evaluate

List of usage examples for org.apache.commons.math.stat.descriptive.moment Variance evaluate

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive.moment Variance evaluate.

Prototype

public double evaluate(final double[] values, final double mean) 

Source Link

Document

Returns the variance of the entries in the input array, using the precomputed mean value.

Usage

From source file:com.clican.pluto.dataprocess.dpl.function.impl.StandardDeviation.java

public Object calculate(List<Map<String, Object>> rowSet)
        throws CalculationException, PrefixAndSuffixException {
    if (rowSet.size() == 0) {
        throw new CalculationException("SharpeRatio??");
    }/*from ww w .j  a  v a  2 s.  c  o  m*/
    double[] values = new double[rowSet.size()];
    double sum = 0;
    for (int i = 0; i < rowSet.size(); i++) {
        Map<String, Object> row = rowSet.get(i);
        Double value = valuePas.getValue(row);
        values[i] = value;
        sum += value;
    }
    double avg = sum / rowSet.size();
    Variance var = new Variance(false);
    return Math.sqrt(var.evaluate(values, avg));
}

From source file:com.clican.pluto.dataprocess.dpl.function.impl.SharpeRatio.java

public Object calculate(List<Map<String, Object>> rowSet)
        throws CalculationException, PrefixAndSuffixException {
    if (rowSet.size() == 0) {
        throw new CalculationException("SharpeRatio??");
    }/*from  w w  w  .  j ava 2  s  .  c om*/

    double[] values = new double[rowSet.size()];
    double sum = 0;
    for (int i = 0; i < rowSet.size(); i++) {
        Map<String, Object> row = rowSet.get(i);
        Double value = valuePas.getValue(row);
        values[i] = value;
        sum += value;
    }
    double avg = sum / (rowSet.size());
    Variance var = new Variance(false);
    Double result = Math.sqrt(var.evaluate(values, avg));
    if (log.isDebugEnabled()) {
        log.debug("FRR[" + avg + "],STDEV[" + result + "]");
    }
    return avg / result;
}

From source file:com.clican.pluto.dataprocess.dpl.function.impl.TrackError.java

/**
 * @param rowSet/*from   w ww  . java  2 s .  c  om*/
 *            List
 * @see com.clican.pluto.dataprocess.dpl.function.MultiRowFunction#calculate(java.util.List)
 */

public Object calculate(List<Map<String, Object>> rowSet)
        throws CalculationException, PrefixAndSuffixException {
    if (rowSet == null || rowSet.size() == 0) {
        throw new CalculationException("??");
    }

    double[] values = new double[rowSet.size()];
    double sum = 0;
    for (int i = 0; i < rowSet.size(); i++) {
        Map<String, Object> row = rowSet.get(i);
        Double fundValue = fundNavList.getValue(row);
        Double indexValue = indexList.getValue(row);
        double value = fundValue.doubleValue() - indexValue.doubleValue();
        values[i] = value;
        sum += value;
    }
    double avg = sum / (rowSet.size());

    Variance var = new Variance(false);
    Double result = Math.sqrt(var.evaluate(values, avg));

    return result;
}

From source file:com.clican.pluto.dataprocess.dpl.function.impl.InformationRatio.java

public Object calculate(List<Map<String, Object>> rowSet)
        throws CalculationException, PrefixAndSuffixException {
    if (rowSet.size() == 0) {
        throw new CalculationException("InformationRatio??");
    }/*from   www  .  j a va  2  s . c  om*/
    List<Double> estimateValueList = new ArrayList<Double>();
    List<Double> referValueList = new ArrayList<Double>();
    Double estimateSum = 0d;
    Double referSum = 0d;
    Double differencingSum = 0d;
    double[] differencingList = new double[rowSet.size()];
    for (int i = 0; i < rowSet.size(); i++) {
        Map<String, Object> row = rowSet.get(i);
        Double estimateValue = estimateVectorPas.getValue(row);
        Double referValue = referVectorPas.getValue(row);
        Double differencing = estimateValue - referValue;
        estimateSum += estimateValue;
        referSum += referValue;
        differencingSum += differencing;
        estimateValueList.add(estimateSum);
        referValueList.add(referValue);
        differencingList[i] = differencing;
    }
    Double estimateAvg = estimateSum / estimateValueList.size();
    Double referAvg = referSum / referValueList.size();

    Variance var = new Variance(false);
    Double standard = Math.sqrt(var.evaluate(differencingList, differencingSum / differencingList.length));
    Double result = (estimateAvg - referAvg) / standard;
    if (log.isDebugEnabled()) {
        log.debug("FR=[" + estimateAvg + "],BR=[" + referAvg + "],=[" + standard + "],information=[" + result
                + "]");
    }
    return result;
}