class BlackScholesFormulaRepository {

  public static double strikeForDelta(
      double spot,
      double spotDelta,
      double timeToExpiry,
      double lognormalVol,
      double interestRate,
      double costOfCarry,
      boolean isCall) {

    ArgChecker.isTrue(spot > 0d, "non-positive/NaN spot; have {}", spot);
    ArgChecker.isTrue(timeToExpiry > 0d, "non-positive/NaN timeToExpiry; have {}", timeToExpiry);
    ArgChecker.isTrue(lognormalVol > 0d, "non-positive/NaN lognormalVol; have {}", lognormalVol);
    ArgChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN");
    ArgChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN");

    ArgChecker.isFalse(Double.isInfinite(spot), "spot is infinite");
    ArgChecker.isFalse(Double.isInfinite(spotDelta), "spotDelta is infinite");
    ArgChecker.isFalse(Double.isInfinite(timeToExpiry), "timeToExpiry is infinite");
    ArgChecker.isFalse(Double.isInfinite(lognormalVol), "lognormalVol is infinite");
    ArgChecker.isFalse(Double.isInfinite(interestRate), "interestRate is infinite");
    ArgChecker.isFalse(Double.isInfinite(costOfCarry), "costOfCarry is infinite");

    double rescaledDelta = spotDelta * Math.exp((-costOfCarry + interestRate) * timeToExpiry);
    ArgChecker.isTrue((isCall && rescaledDelta > 0d && rescaledDelta < 1.) || (!isCall && spotDelta < 0d && rescaledDelta > -1.),
        "delta/Math.exp((costOfCarry - interestRate) * timeToExpiry) out of range, ", rescaledDelta);

    double sigmaRootT = lognormalVol * Math.sqrt(timeToExpiry);
    double rescaledSpot = spot * Math.exp(costOfCarry * timeToExpiry);

    int sign = isCall ? 1 : -1;
    double d1 = sign * NORMAL.getInverseCDF(sign * rescaledDelta);
    return rescaledSpot * Math.exp(-d1 * sigmaRootT + 0.5 * sigmaRootT * sigmaRootT);
  }

  private  BlackScholesFormulaRepository();

}