List of usage examples for java.lang Double doubleToLongBits
@HotSpotIntrinsicCandidate public static long doubleToLongBits(double value)
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.formula.AmericanVanillaOption.java
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (_isCall ? 1231 : 1237); long temp;//from w w w .j a v a 2 s.c om temp = Double.doubleToLongBits(_strike); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(_timeToExpiry); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; }
From source file:com.opengamma.analytics.financial.model.volatility.NormalImpliedVolatilityFormula.java
/** * Computes the implied volatility from the price in a normally distributed asset price world. * @param data The model data. The data volatility, if not zero, is used as a starting point for the volatility search. * @param option The option./* w w w. ja v a2s . c o m*/ * @param optionPrice The option price. * @return The implied volatility. */ public double getImpliedVolatility(final NormalFunctionData data, final EuropeanVanillaOption option, final double optionPrice) { final double numeraire = data.getNumeraire(); final boolean isCall = option.isCall(); final double f = data.getForward(); final double k = option.getStrike(); final double intrinsicPrice = numeraire * Math.max(0, (isCall ? 1 : -1) * (f - k)); Validate.isTrue(optionPrice > intrinsicPrice || CompareUtils.closeEquals(optionPrice, intrinsicPrice, 1e-6), "option price (" + optionPrice + ") less than intrinsic value (" + intrinsicPrice + ")"); if (Double.doubleToLongBits(optionPrice) == Double.doubleToLongBits(intrinsicPrice)) { return 0.0; } double sigma = (Math.abs(data.getNormalVolatility()) < 1E-10 ? 0.3 * f : data.getNormalVolatility()); NormalFunctionData newData = new NormalFunctionData(f, numeraire, sigma); final double maxChange = 0.5 * f; double[] priceDerivative = new double[3]; double price = NORMAL_PRICE_FUNCTION.getPriceAdjoint(option, newData, priceDerivative); double vega = priceDerivative[1]; double change = (price - optionPrice) / vega; double sign = Math.signum(change); change = sign * Math.min(maxChange, Math.abs(change)); if (change > 0 && change > sigma) { change = sigma; } int count = 0; while (Math.abs(change) > EPS) { sigma -= change; newData = new NormalFunctionData(f, numeraire, sigma); price = NORMAL_PRICE_FUNCTION.getPriceAdjoint(option, newData, priceDerivative); vega = priceDerivative[1]; change = (price - optionPrice) / vega; sign = Math.signum(change); change = sign * Math.min(maxChange, Math.abs(change)); if (change > 0 && change > sigma) { change = sigma; } if (count++ > MAX_ITERATIONS) { final BracketRoot bracketer = new BracketRoot(); final BisectionSingleRootFinder rootFinder = new BisectionSingleRootFinder(EPS); final Function1D<Double, Double> func = new Function1D<Double, Double>() { @SuppressWarnings({ "synthetic-access" }) @Override public Double evaluate(final Double volatility) { final NormalFunctionData myData = new NormalFunctionData(data.getForward(), data.getNumeraire(), volatility); return NORMAL_PRICE_FUNCTION.getPriceFunction(option).evaluate(myData) - optionPrice; } }; final double[] range = bracketer.getBracketedPoints(func, 0.0, 10.0); return rootFinder.getRoot(func, range[0], range[1]); } } return sigma; }
From source file:com.opengamma.analytics.financial.model.option.definition.AsymmetricPowerOptionDefinition.java
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); long temp;/*from w ww.java 2 s. c o m*/ temp = Double.doubleToLongBits(_power); result = prime * result + (int) (temp ^ temp >>> 32); return result; }
From source file:com.opengamma.analytics.financial.var.EmpiricalDistributionVaRParameters.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//ww w. j a v a 2s.com if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final EmpiricalDistributionVaRParameters other = (EmpiricalDistributionVaRParameters) obj; if (Double.doubleToLongBits(_horizon) != Double.doubleToLongBits(other._horizon)) { return false; } if (Double.doubleToLongBits(_periods) != Double.doubleToLongBits(other._periods)) { return false; } if (Double.doubleToLongBits(_quantile) != Double.doubleToLongBits(other._quantile)) { return false; } return true; }
From source file:com.opengamma.analytics.financial.model.option.definition.EuropeanStandardBarrierOptionDefinition.java
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((_barrier == null) ? 0 : _barrier.hashCode()); long temp;//from w ww. j a va 2s .co m temp = Double.doubleToLongBits(_rebate); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; }
From source file:com.opengamma.analytics.financial.model.option.definition.Barrier.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//from ww w .j a va 2 s . com if (!(obj instanceof Barrier)) { return false; } final Barrier other = (Barrier) obj; return _barrier == other._barrier && _knock == other._knock && _observation == other._observation && Double.doubleToLongBits(_level) == Double.doubleToLongBits(other._level); }
From source file:com.opengamma.analytics.financial.var.NormalVaRParameters.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/*from w w w. j ava 2 s .c om*/ if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final NormalVaRParameters other = (NormalVaRParameters) obj; if (Double.doubleToLongBits(_horizon) != Double.doubleToLongBits(other._horizon)) { return false; } if (Double.doubleToLongBits(_periods) != Double.doubleToLongBits(other._periods)) { return false; } if (Double.doubleToLongBits(_quantile) != Double.doubleToLongBits(other._quantile)) { return false; } return true; }
From source file:com.opengamma.analytics.financial.simpleinstruments.derivative.SimpleFuture.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/*from ww w .j a va 2 s .c o m*/ if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } SimpleFuture other = (SimpleFuture) obj; if (Double.doubleToLongBits(_expiry) != Double.doubleToLongBits(other._expiry)) { return false; } if (Double.doubleToLongBits(_referencePrice) != Double.doubleToLongBits(other._referencePrice)) { return false; } if (Double.doubleToLongBits(_settlement) != Double.doubleToLongBits(other._settlement)) { return false; } if (Double.doubleToLongBits(_unitAmount) != Double.doubleToLongBits(other._unitAmount)) { return false; } if (!ObjectUtils.equals(_currency, other._currency)) { return false; } return true; }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.formula.BlackFunctionData.java
@Override public int hashCode() { final int prime = 31; int result = 1; long temp;// w w w .ja v a2 s . c om temp = Double.doubleToLongBits(_numeraire); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(_f); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(_sigma); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; }
From source file:com.opengamma.analytics.financial.model.volatility.curve.FXVannaVolgaVolatilityCurveDataBundle.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/* w ww .java2 s.com*/ if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final FXVannaVolgaVolatilityCurveDataBundle other = (FXVannaVolgaVolatilityCurveDataBundle) obj; if (Double.doubleToLongBits(_atm) != Double.doubleToLongBits(other._atm)) { return false; } if (Double.doubleToLongBits(_delta) != Double.doubleToLongBits(other._delta)) { return false; } if (!ObjectUtils.equals(_maturity, other._maturity)) { return false; } if (Double.doubleToLongBits(_riskReversal) != Double.doubleToLongBits(other._riskReversal)) { return false; } if (Double.doubleToLongBits(_vegaWeightedButterfly) != Double .doubleToLongBits(other._vegaWeightedButterfly)) { return false; } return true; }