Reputation: 2793
we used the Extreme Numerics library from Extreme Optimization (http://www.extremeoptimization.com) for our calculation kernel.
// portfolio risk is inverse normal cumulative distribution function
double risk = NormalDistribution.InverseDistributionFunction(
_riskProbabilityLevel,
mean,
stdev);
The problem is now we are moving from C# to Java and I don't really know all that much about Java but have been tasked with re-writing this particular function.
I have values to test against:
RiskProbabilityLevel = 0.02
Mean = 0.06618
Standard Dev = 0.057196166520267355
Risk = 0.051286461995869864
but in looking thru the various functions in math3.distribution.NormalDistribution
libraries I can't find what might be equivalent.
Any direction or help would be appreciated. thanks.
Upvotes: 0
Views: 4788
Reputation: 2034
I think you can use this library. It's called apache commons.math3
. It's very popular. From the docs supplied by http://www.extremeoptimization.com I think you can use the following code:
import org.apache.commons.math3.distribution.NormalDistribution;
public class TestProbabilites {
public static void main(String[] args) {
double riskProbabilityLevel = 0.02D;
double mean = 0.06618D;
double standardDev = 0.057196166520267355D;
double expectedRisk = 0.051286461995869864D;
NormalDistribution distribution = new NormalDistribution(mean, standardDev);
double outcomeRisk = distribution.inverseCumulativeProbability(riskProbabilityLevel);
}
}
But you have to remember to add the apache.commons.math3
library added to your project using Maven
or Gradle
or some other dependencies manager.
Hopes this helps.
Upvotes: 10