private static (double var, double es) GetVarAndEsAtConfidenceLvl(ImmutableList <double> returnsSet, int confidenceLevel) { int fullCount = returnsSet.Count; int confidenceLvlCount = fullCount * (100 - confidenceLevel) / 100; ImmutableList <double> confidenceLvlReturnsList = returnsSet.Take(confidenceLvlCount).ToImmutableList(); double var = confidenceLvlReturnsList.Last(); double es = confidenceLvlReturnsList.AsParallel().Average(); return(var, es); }