List of usage examples for org.apache.commons.math.stat.descriptive.moment Variance Variance
public Variance(Variance original)
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 ww.ja va2 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); 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.StandardDeviation.java
public Object calculate(List<Map<String, Object>> rowSet) throws CalculationException, PrefixAndSuffixException { if (rowSet.size() == 0) { throw new CalculationException("SharpeRatio??"); }/* w w w.j a v a 2 s . com*/ 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.TrackError.java
/** * @param rowSet//from w w w . ja va 2s . co m * 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.Beta.java
private double getBeta(double[] referValueList, double[] estimateValueList) { Variance var = new Variance(false); Covariance cov = new Covariance(); double varValue = var.evaluate(referValueList); double covValue = cov.covariance(referValueList, estimateValueList, false); if (log.isDebugEnabled()) { log.debug("Covariance=[" + covValue + "],Variance=[" + varValue + "]"); }/*from w w w.j av a 2 s . c o m*/ Double beta = covValue / varValue; return beta; }
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 w ww.java 2 s .co m 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; }
From source file:Covariance.java
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. /*from w w w . j ava 2s .co m*/ * @param matrix input matrix (must have at least two columns and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), i, matrix.getColumn(j), j, biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }
From source file:org.beedraz.semantics_II.expression.number.real.double64.stat.DoublePopulationVarianceBeed.java
/** * @post getSource() == null;// w ww .ja v a 2s . com * @post getDouble() == null; * @post owner != null ? owner.registerAggregateElement(this); */ public DoublePopulationVarianceBeed(AggregateBeed owner) { super(new Variance(false), owner); }
From source file:org.beedraz.semantics_II.expression.number.real.double64.stat.DoubleSampleVarianceBeed.java
/** * @post getSource() == null;//from w w w .j a v a 2 s . c o m * @post getDouble() == null; * @post owner != null ? owner.registerAggregateElement(this); */ public DoubleSampleVarianceBeed(AggregateBeed owner) { super(new Variance(true), owner); }
From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java
/** * The sample variance can be calculated in two ways: if the dataset is considered as the entire population then the * sample variance is simply the second central moment: * /* w w w . ja v a 2 s .co m*/ * <pre> * sum((x_i - m)^2)/N * where {x_i} are set of N population values and m is the mean * m = sum(x_i)/N * </pre> * * Otherwise, if the dataset is a set of samples (with replacement) from the population then * * <pre> * sum((x_i - m)^2)/(N-1) * where {x_i} are set of N sample values and m is the unbiased estimate of the mean * m = sum(x_i)/N * </pre> * * Note that the second definition is also the unbiased estimator of population variance. * * @param isDatasetWholePopulation * @return sample variance */ public Number variance(boolean isDatasetWholePopulation) { SummaryStatistics stats = getStatistics(); if (isDatasetWholePopulation) { StorelessUnivariateStatistic oldVar = stats.getVarianceImpl(); stats.setVarianceImpl(new Variance(false)); Number var = stats.getVariance(); stats.setVarianceImpl(oldVar); return var; } return stats.getVariance(); }