List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * remove me/*from ww w . j a va 2 s. co m*/ */ public void doRemove() { super.doRemove(); clearAnnotations(segments); clearAnnotations(wayPoints); clearAnnotations(rangeFilters); firePropertyChange(PROP_TIMERANGE, null, segments); if ((rangeFilters.size() == 0) || (dataChoiceWrappers.size() == 0)) { return; } DataChoice dataChoice = ((DataChoiceWrapper) dataChoiceWrappers.get(0)).getDataChoice(); getDisplayControl().doShare(DisplayControlImpl.SHARE_SELECTRANGE, new Object[] { dataChoice, new ucar.unidata.util.Range(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) }); }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Iterates over the data items of the xyz dataset to find * the z-dimension bounds./*ww w . ja v a2s. c o m*/ * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval include the z-interval (if the dataset has a * z-interval. * * @return The range (possibly <code>null</code>). */ public static Range iterateZBounds(XYZDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = dataset.getZValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of x-values in the specified dataset for the * data items belonging to the visible series. * /*from w ww. j av a 2 s . c om*/ * @param dataset the dataset ({@code null} not permitted). * @param visibleSeriesKeys the visible series keys ({@code null} not * permitted). * @param includeInterval a flag that determines whether or not the * y-interval for the dataset is included (this only applies if the * dataset is an instance of IntervalXYDataset). * * @return The x-range (possibly {@code null}). * * @since 1.0.13 */ public static Range iterateToFindDomainBounds(XYDataset dataset, List visibleSeriesKeys, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double xvalue = ixyd.getXValue(series, item); double lvalue = ixyd.getStartXValue(series, item); double uvalue = ixyd.getEndXValue(series, item); if (!Double.isNaN(xvalue)) { minimum = Math.min(minimum, xvalue); maximum = Math.max(maximum, xvalue); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } else { // standard case - plain XYDataset Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); if (!Double.isNaN(x)) { minimum = Math.min(minimum, x); maximum = Math.max(maximum, x); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the range of x-values in the specified dataset for the * data items belonging to the visible series. * /*from w w w .j av a2 s. c o m*/ * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> not * permitted). * @param includeInterval a flag that determines whether or not the * y-interval for the dataset is included (this only applies if the * dataset is an instance of IntervalXYDataset). * * @return The x-range (possibly <code>null</code>). * * @since 1.0.13 */ public static Range iterateToFindDomainBounds(XYDataset dataset, List visibleSeriesKeys, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double lvalue = ixyd.getStartXValue(series, item); double uvalue = ixyd.getEndXValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } else { // standard case - plain XYDataset Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); if (!Double.isNaN(x)) { minimum = Math.min(minimum, x); maximum = Math.max(maximum, x); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The vomma (aka volga) of an option, i.e. second order derivative of the option spot price with respect to the implied volatility. * @param spot The spot value of the underlying * @param strike The Strike/* w w w . j a v a2s.c om*/ * @param timeToExpiry The time-to-expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost-of-carry rate * @return The spot vomma */ @ExternalFunction public static double vomma(final double spot, final double strike, final double timeToExpiry, final double lognormalVol, final double interestRate, final double costOfCarry) { ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot); ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike); ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry); ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol); ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN"); ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN"); final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; if (Double.isNaN(sigmaRootT)) { sigmaRootT = 1.; //ref value is returned } if (spot > LARGE * strike || strike > LARGE * spot || rootT < SMALL) { return 0.; } double d1 = 0.; double d1d2Mod = 0.; if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE) || rootT > LARGE) { final double costOvVol = (Math.abs(costOfCarry) < SMALL && lognormalVol < SMALL) ? Math.signum(costOfCarry) : costOfCarry / lognormalVol; final double coefD1 = costOvVol + 0.5 * lognormalVol; final double coefD1D2Mod = costOvVol * costOvVol / lognormalVol - 0.25 * lognormalVol; final double tmpD1 = coefD1 * rootT; final double tmpD1d2Mod = coefD1D2Mod * rootT * timeToExpiry; d1 = Double.isNaN(tmpD1) ? 0. : tmpD1; d1d2Mod = Double.isNaN(tmpD1d2Mod) ? 1. : tmpD1d2Mod; } else { if (lognormalVol > LARGE) { d1 = 0.5 * sigmaRootT; d1d2Mod = -0.25 * sigmaRootT * timeToExpiry; } else { if (lognormalVol < SMALL) { final double d1Tmp = (Math.log(spot / strike) / rootT + costOfCarry * rootT) / lognormalVol; d1 = Double.isNaN(d1Tmp) ? 1. : d1Tmp; d1d2Mod = d1 * d1 * rootT / lognormalVol; } else { final double tmp = Math.log(spot / strike) / sigmaRootT + costOfCarry * rootT / lognormalVol; d1 = tmp + 0.5 * sigmaRootT; d1d2Mod = (tmp * tmp - 0.25 * sigmaRootT * sigmaRootT) * rootT / lognormalVol; } } } // if (Double.isNaN(d1) || Double.isNaN(d1d2Mod)) { // throw new IllegalArgumentException("NaN found"); // } double coef = 0.; if ((interestRate > LARGE && costOfCarry > LARGE) || (-interestRate > LARGE && -costOfCarry > LARGE) || Math.abs(costOfCarry - interestRate) < SMALL) { coef = 1.; //ref value is returned } else { final double rate = costOfCarry - interestRate; if (rate > LARGE) { return costOfCarry > LARGE ? 0. : (d1d2Mod >= 0. ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY); } if (-rate > LARGE) { return 0.; } coef = Math.exp(rate * timeToExpiry); } final double norm = NORMAL.getPDF(d1); double tmp = d1d2Mod * spot * coef; if (Double.isNaN(tmp)) { tmp = coef; } return norm < SMALL ? 0. : norm * tmp; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of y-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range.//from w ww. ja v a2 s. com * * @param dataset the dataset ({@code null} not permitted). * @param visibleSeriesKeys the visible series keys ({@code null} not * permitted). * @param xRange the x-range ({@code null} not permitted). * @param includeInterval a flag that determines whether or not the * y-interval for the dataset is included (this only applies if the * dataset is an instance of IntervalXYDataset). * * @return The y-range (possibly {@code null}). * * @since 1.0.13 */ public static Range iterateToFindRangeBounds(XYDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); Args.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; // handle three cases by dataset type if (includeInterval && dataset instanceof OHLCDataset) { // handle special case of OHLCDataset OHLCDataset ohlc = (OHLCDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = ohlc.getXValue(series, item); if (xRange.contains(x)) { double lvalue = ohlc.getLowValue(series, item); double uvalue = ohlc.getHighValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } } else if (includeInterval && dataset instanceof BoxAndWhiskerXYDataset) { // handle special case of BoxAndWhiskerXYDataset BoxAndWhiskerXYDataset bx = (BoxAndWhiskerXYDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = bx.getXValue(series, item); if (xRange.contains(x)) { Number lvalue = bx.getMinRegularValue(series, item); Number uvalue = bx.getMaxRegularValue(series, item); if (lvalue != null) { minimum = Math.min(minimum, lvalue.doubleValue()); } if (uvalue != null) { maximum = Math.max(maximum, uvalue.doubleValue()); } } } } } else if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = ixyd.getXValue(series, item); if (xRange.contains(x)) { double yvalue = ixyd.getYValue(series, item); double lvalue = ixyd.getStartYValue(series, item); double uvalue = ixyd.getEndYValue(series, item); if (!Double.isNaN(yvalue)) { minimum = Math.min(minimum, yvalue); maximum = Math.max(maximum, yvalue); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } } else { // standard case - plain XYDataset Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(y)) { minimum = Math.min(minimum, y); maximum = Math.max(maximum, y); } } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:net.pms.util.Rational.java
/** * Converts this {@link Rational} to a {@code double}. This conversion is * similar to the <i>narrowing primitive conversion</i> from {@code double} * to {@code float} as defined in section 5.1.3 of <cite>The Java™ * Language Specification</cite>: if this {@link Rational} has too great a * magnitude to represent as a {@code double}, it will be converted to * {@link Double#NEGATIVE_INFINITY} or {@link Double#POSITIVE_INFINITY} as * appropriate.//from w w w . j a v a 2 s. com * <p> * Note that even when the return value is finite, this conversion can lose * information about the precision of the {@link Rational} value. * * @return This {@link Rational} converted to a {@code double}. */ @Override public double doubleValue() { if (isNaN()) { return Double.NaN; } if (isInfinitePositive()) { return Double.POSITIVE_INFINITY; } if (isInfiniteNegative()) { return Double.NEGATIVE_INFINITY; } return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), MathContext.DECIMAL64) .doubleValue(); }
From source file:edu.cmu.tetrad.util.StatUtils.java
public static double entropy(int numBins, double[] _f) { double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; for (double x : _f) { if (x < min) min = x;/* w ww . ja v a2 s. c o m*/ if (x > max) max = x; } int[] v = new int[numBins]; double width = max - min; for (double x : _f) { double x3 = (x - min) / width; // 0 to 1 int bin = (int) (x3 * (numBins - 1)); // 0 to numBins - 1 v[bin]++; } // Calculate entropy. double sum = 0.0; for (int aV : v) { if (aV != 0) { double p = aV / (double) (numBins - 1); sum += p * Math.log(p); } } return -sum; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the range of y-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range./*www . jav a 2 s.co m*/ * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> not * permitted). * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval for the dataset is included (this only applies if the * dataset is an instance of IntervalXYDataset). * * @return The y-range (possibly <code>null</code>). * * @since 1.0.13 */ public static Range iterateToFindRangeBounds(XYDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); ParamChecks.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; // handle three cases by dataset type if (includeInterval && dataset instanceof OHLCDataset) { // handle special case of OHLCDataset OHLCDataset ohlc = (OHLCDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = ohlc.getXValue(series, item); if (xRange.contains(x)) { double lvalue = ohlc.getLowValue(series, item); double uvalue = ohlc.getHighValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } } else if (includeInterval && dataset instanceof BoxAndWhiskerXYDataset) { // handle special case of BoxAndWhiskerXYDataset BoxAndWhiskerXYDataset bx = (BoxAndWhiskerXYDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = bx.getXValue(series, item); if (xRange.contains(x)) { Number lvalue = bx.getMinRegularValue(series, item); Number uvalue = bx.getMaxRegularValue(series, item); if (lvalue != null) { minimum = Math.min(minimum, lvalue.doubleValue()); } if (uvalue != null) { maximum = Math.max(maximum, uvalue.doubleValue()); } } } } } else if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = ixyd.getXValue(series, item); if (xRange.contains(x)) { double lvalue = ixyd.getStartYValue(series, item); double uvalue = ixyd.getEndYValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } } else { // standard case - plain XYDataset Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(y)) { minimum = Math.min(minimum, y); maximum = Math.max(maximum, y); } } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The vega bleed of an option, i.e. second order derivative of the option spot price, once to the volatility and once to the time. * @param spot The spot value of the underlying * @param strike The Strike//from ww w . j a v a 2 s.c o m * @param timeToExpiry The time-to-expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost-of-carry rate * @return The spot vomma */ @ExternalFunction public static double vegaBleed(final double spot, final double strike, final double timeToExpiry, final double lognormalVol, final double interestRate, final double costOfCarry) { ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot); ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike); ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry); ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol); ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN"); ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN"); final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; if (Double.isNaN(sigmaRootT)) { sigmaRootT = 1.; //ref value is returned } if (spot > LARGE * strike || strike > LARGE * spot || rootT < SMALL) { return 0.; } double d1 = 0.; double extra = 0.; if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE) || rootT > LARGE) { final double costOvVol = (Math.abs(costOfCarry) < SMALL && lognormalVol < SMALL) ? Math.signum(costOfCarry) : costOfCarry / lognormalVol; final double coefD1 = costOvVol + 0.5 * lognormalVol; final double tmpD1 = coefD1 * rootT; d1 = Double.isNaN(tmpD1) ? 0. : tmpD1; final double coefExtra = interestRate - 0.5 * costOfCarry + 0.5 * costOvVol * costOvVol + 0.125 * lognormalVol * lognormalVol; final double tmpExtra = Double.isNaN(coefExtra) ? rootT : coefExtra * rootT; extra = Double.isNaN(tmpExtra) ? 1. - 0.5 / rootT : tmpExtra - 0.5 / rootT; } else { if (lognormalVol > LARGE) { d1 = 0.5 * sigmaRootT; extra = 0.125 * lognormalVol * sigmaRootT; } else { if (lognormalVol < SMALL) { final double resLogRatio = Math.log(spot / strike) / rootT; final double d1Tmp = (resLogRatio + costOfCarry * rootT) / lognormalVol; d1 = Double.isNaN(d1Tmp) ? 1. : d1Tmp; final double tmpExtra = (-0.5 * resLogRatio * resLogRatio / rootT + 0.5 * costOfCarry * costOfCarry * rootT) / lognormalVol / lognormalVol; extra = Double.isNaN(tmpExtra) ? 1. : extra; } else { final double resLogRatio = Math.log(spot / strike) / sigmaRootT; final double tmp = resLogRatio + costOfCarry * rootT / lognormalVol; d1 = tmp + 0.5 * sigmaRootT; double pDivTmp = interestRate - 0.5 * costOfCarry * (1. - costOfCarry / lognormalVol / lognormalVol); double pDiv = Double.isNaN(pDivTmp) ? rootT : pDivTmp * rootT; extra = pDiv - 0.5 / rootT - 0.5 * resLogRatio * resLogRatio / rootT + 0.125 * lognormalVol * sigmaRootT; } } } // if (Double.isNaN(d1) || Double.isNaN(extra)) { // throw new IllegalArgumentException("NaN found"); // } double coef = 0.; if ((interestRate > LARGE && costOfCarry > LARGE) || (-interestRate > LARGE && -costOfCarry > LARGE) || Math.abs(costOfCarry - interestRate) < SMALL) { coef = 1.; //ref value is returned } else { final double rate = costOfCarry - interestRate; if (rate > LARGE) { return costOfCarry > LARGE ? 0. : (extra >= 0. ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY); } if (-rate > LARGE) { return 0.; } coef = Math.exp(rate * timeToExpiry); } final double norm = NORMAL.getPDF(d1); double tmp = spot * coef * extra; if (Double.isNaN(tmp)) { tmp = coef; } return norm < SMALL ? 0. : tmp * norm; }