@Override public Double apply(Double x) { return vega(forward, strike, timeToExpiry, x); } };
@Override public Double apply(Double volatility) { return numeraire * price(forward, strike, timeToExpiry, volatility, putCall) - optionPrice; } };
@Override public Double apply(Double volatility) { return NormalFormulaRepository .impliedVolatilityFromBlackApproximated(forward, strike, timeToExpiry, volatility) - normalVolatility; } };
private double impliedVolatility( NormalFunctionData data, EuropeanVanillaOption option, double price) { return NormalFormulaRepository.impliedVolatility( price, data.getForward(), option.getStrike(), option.getTimeToExpiry(), data.getNormalVolatility(), data.getNumeraire(), option.getPutCall()); }
@SuppressWarnings("synthetic-access") @Override public Double apply(NormalFunctionData data) { ArgChecker.notNull(data, "data"); return data.getNumeraire() * NormalFormulaRepository.price( data.getForward(), option.getStrike(), option.getTimeToExpiry(), data.getNormalVolatility(), option.getPutCall()); } };
private void priceCheck(double[] strikes) { for (int i = 0; i < N; i++) { double ivNormalComputed = NormalFormulaRepository .impliedVolatilityFromBlackApproximated(FORWARD, strikes[i], T, SIGMA_BLACK[i]); double priceNormalComputed = NormalFormulaRepository.price(FORWARD, strikes[i], T, ivNormalComputed, PutCall.CALL) * DF; double priceBlack = BlackFormulaRepository.price(FORWARD, strikes[i], T, SIGMA_BLACK[i], true) * DF; assertEquals(priceNormalComputed, priceBlack, TOLERANCE_PRICE); } }
private void priceCheck(double[] strikes) { for (int i = 0; i < N; i++) { double ivBlackComputed = BlackFormulaRepository .impliedVolatilityFromNormalApproximated(FORWARD, strikes[i], TIME_TO_EXPIRY, SIGMA_NORMAL[i]); double priceBlackComputed = BlackFormulaRepository .price(FORWARD, strikes[i], TIME_TO_EXPIRY, ivBlackComputed, true); double priceNormal = NormalFormulaRepository .price(FORWARD, strikes[i], TIME_TO_EXPIRY, SIGMA_NORMAL[i], CALL); assertEquals(priceNormal, priceBlackComputed, TOLERANCE_PRICE); } }
/** * standard in-out parity holds if r=0. */ public void inOutParity() { double upIn = PRICER.price(SPOT, EXPIRY_TIME, RATE_DOM, RATE_DOM, VOLATILITY, BARRIER_UP_IN); double upOut = PRICER.price(SPOT, EXPIRY_TIME, RATE_DOM, RATE_DOM, VOLATILITY, BARRIER_UP_OUT); double downIn = PRICER.price(SPOT, EXPIRY_TIME, RATE_DOM, RATE_DOM, VOLATILITY, BARRIER_DOWN_IN); double downOut = PRICER.price(SPOT, EXPIRY_TIME, RATE_DOM, RATE_DOM, VOLATILITY, BARRIER_DOWN_OUT); assertRelative(upIn + upOut, SPOT, TOL); assertRelative(downIn + downOut, SPOT, TOL); }
/** * standard in-out parity holds if r=0. */ public void inOutParity() { double upIn = PRICER.price(SPOT, EXPIRY_TIME, COST_OF_CARRY, 0d, VOLATILITY, BARRIER_UP_IN); double upOut = PRICER.price(SPOT, EXPIRY_TIME, COST_OF_CARRY, 0d, VOLATILITY, BARRIER_UP_OUT); double downIn = PRICER.price(SPOT, EXPIRY_TIME, COST_OF_CARRY, 0d, VOLATILITY, BARRIER_DOWN_IN); double downOut = PRICER.price(SPOT, EXPIRY_TIME, COST_OF_CARRY, 0d, VOLATILITY, BARRIER_DOWN_OUT); assertRelative(upIn + upOut, 1d); assertRelative(downIn + downOut, 1d); }
public void intrinsic_price() { NormalFunctionData data = NormalFunctionData.of(1.0, 1.0, 0.01); EuropeanVanillaOption option1 = EuropeanVanillaOption.of(0.5, 1.0, PutCall.CALL); assertThrowsIllegalArg(() -> impliedVolatility(data, option1, 1e-6)); EuropeanVanillaOption option2 = EuropeanVanillaOption.of(1.5, 1.0, PutCall.PUT); assertThrowsIllegalArg(() -> impliedVolatility(data, option2, 1e-6)); }
@Override public Double apply(Double x) { return price(forward, strike, timeToExpiry, x, isCall); } };
/** * The Black price with numeraire 1 as function of the strike. * * @param strike the strike. * @return the Black price. */ double bs(double strike) { return sabrExtrapolation.price(strike + shift, PutCall.CALL); } }
/** * Computes the implied volatility. * * @param optionPrice the option price * @return the volatility */ public double impliedVolatility(double optionPrice) { return impliedVolatility(optionPrice, VOL_GUESS); }
/** * Gets the three fitting parameters derivatives with respect to the SABR parameters. * * @return the parameters derivative */ public double[][] getParameterDerivativeSabr() { if (parameterDerivativeSabr == null) { parameterDerivativeSabr = computesParametersDerivativeSabr(); } return parameterDerivativeSabr; }
/** * Gets the three fitting parameters derivatives with respect to the forward. * * @return the parameters derivative */ public double[] getParameterDerivativeForward() { if (parameterDerivativeForward == null) { parameterDerivativeForward = computesParametersDerivativeForward(); } return parameterDerivativeForward; }
/** * Data bundle for pricing in a normal framework. * That is, the forward value of the underlying asset is a martingale in the chosen numeraire measure. * * @param forward the forward value of the underlying asset, such as forward value of a stock, or forward Libor rate * @param numeraire the numeraire associated with the equation * @param normalVolatility the normal volatility (sigma) * @return the function data */ public static NormalFunctionData of(double forward, double numeraire, double normalVolatility) { return new NormalFunctionData(forward, numeraire, normalVolatility); }
/** * Obtains an instance. * * @param strike the strike * @param timeToExpiry the time to expiry, year fraction * @param putCall whether the option is put or call. * @return the option definition */ public static EuropeanVanillaOption of(double strike, double timeToExpiry, PutCall putCall) { return new EuropeanVanillaOption(strike, timeToExpiry, putCall); }
/** * Upper barrier level is very high. */ public void largeBarrierTest() { SimpleConstantContinuousBarrier in = SimpleConstantContinuousBarrier.of(BarrierType.UP, KnockType.KNOCK_IN, 1.0e4); SimpleConstantContinuousBarrier out = SimpleConstantContinuousBarrier .of(BarrierType.UP, KnockType.KNOCK_OUT, 1.0e4); double upIn = PRICER.price(SPOT, EXPIRY_TIME, COST_OF_CARRY, RATE_DOM, VOLATILITY, in); double upOut = PRICER.price(SPOT, EXPIRY_TIME, COST_OF_CARRY, RATE_DOM, VOLATILITY, out); assertRelative(upIn, 0d, TOL); assertRelative(upOut, FWD_FX * DF_DOM, TOL); }
@Override public double priceVega(double expiry, PutCall putCall, double strike, double forward, double volatility) { return BlackFormulaRepository.vega(forward, strike, expiry, volatility); }
@Override public Double apply(Double volatility) { return NormalFormulaRepository .impliedVolatilityFromBlackApproximated(forward, strike, timeToExpiry, volatility) - normalVolatility; } };