Pricing { public static Double probabilityCorrect(Double p, Integer k) { if (k < 0) return null; if (k == 0) return 0.5; if (p > 1) return null; if (p < 0) return null; if (p == 0.5) return 0.5; if (p < 0.5) { p = 1 - p; } Double result = 0.0; int low = (int) Math.ceil(0.5 * k + 0.5); for (int i = low; i <= k; i++) { result += Math.exp(Stat.logBinom(k, i) + i * Math.log(p) + (k - i) * Math.log(1 - p)); } if (k % 2 == 0) { result += Math.exp(Stat.logBinom(k, k / 2) + (k / 2) * Math.log(p) + (k / 2) * Math.log(1 - p)); } return result; }  static double getNormalizedP_simple(double q_exp); static double getNormalizedQexp_simple(double p); static Double probabilityCorrect(Double p, Integer k); static Double pricingFactor(double from, double to); static void main(String[] args);  }
@Ignore("Pricing - obsole") @Test public final void testProbabilityCorrectTestOnNaN() { for (double p=0; p<1.05; p+=0.05) { for (int k=-1; k<=100; k++) { Double probabilityCorrect = Pricing.probabilityCorrect(new Double(p), new Integer(k)); if (probabilityCorrect!=null) assertFalse("result "+probabilityCorrect+" should be a number or null",Double.isNaN(probabilityCorrect)); } } }
@Test public final void testProbabilityCorrectTestOnNegativeProbability() { for (double p=-10; p<-0.05; p+=0.05) { for (int k=-50; k<0; k++) { Double probabilityCorrect = Pricing.probabilityCorrect(new Double(p), new Integer(k)); assertNull(probabilityCorrect); } } }
@Ignore("Pricing - obsole") @Test public final void testProbabilityCorrectTestOnRange() { for (double p=0.5; p<1.0; p+=0.05) { for (int k=0; k<=100; k++) { Double probabilityCorrect = Pricing.probabilityCorrect(new Double(p), new Integer(k)); assertTrue("probability "+probabilityCorrect+"is out of [0,1]",probabilityCorrect>=0 && probabilityCorrect<=1); } } }