/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void negativeTimeErrorPriceTest() { BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[1], -TIME_TO_EXPIRY, VOLS[1], INTEREST_RATES[1], COST_OF_CARRY, true); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void negativeVolErrorPriceTest() { BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[1], TIME_TO_EXPIRY, -0.5, INTEREST_RATES[1], COST_OF_CARRY, true); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void negativeStrikeErrorPriceTest() { BlackScholesFormulaRepository.price( SPOT, -STRIKES_INPUT[1], TIME_TO_EXPIRY, VOLS[1], INTEREST_RATES[1], COST_OF_CARRY, true); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void nanCarryErrorPriceTest() { BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[1], TIME_TO_EXPIRY, VOLS[1], INTEREST_RATES[1], NAN, true); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void negativeSpotErrorPriceTest() { BlackScholesFormulaRepository.price( -SPOT, STRIKES_INPUT[1], TIME_TO_EXPIRY, VOLS[1], INTEREST_RATES[1], COST_OF_CARRY, true); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void nanIntErrorPriceTest() { BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[1], TIME_TO_EXPIRY, VOLS[1], NAN, COST_OF_CARRY, true); }
for (int k = 0; k < nInt; ++k) { double price = BlackScholesFormulaRepository.price(SPOT, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true); assertEquals(price, PrecomputedCallPrice[i][j][k], Math.max(PrecomputedCallPrice[i][j][k] * EPS, EPS)); for (int k = 0; k < nInt; ++k) { double call = BlackScholesFormulaRepository.price(SPOT, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true); double put = BlackScholesFormulaRepository.price(SPOT, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, false); double ref =
assetPriceLocal[j] = assetTmp; double impliedVol = impliedVolatilitySurface.apply(DoublesPair.of(timePrim[i], assetPriceLocal[j])); callOptionPrice[j] = BlackScholesFormulaRepository.price( spot, assetPriceLocal[j], timePrim[i], impliedVol, zeroRate, zeroCostRate, true); assetTmp *= downFactor; assetPriceLocal[j] = assetTmp; double impliedVol = impliedVolatilitySurface.apply(DoublesPair.of(timePrim[i], assetPriceLocal[j])); putOptionPrice[j] = BlackScholesFormulaRepository.price( spot, assetPriceLocal[j], timePrim[i], impliedVol, zeroRate, zeroCostRate, false); assetTmp *= upFactor;
double strike = STRIKES_INPUT[i]; double vol = VOLS[j]; double resC1 = BlackScholesFormulaRepository.price( 1.e-12 * strike, strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, true); double refC1 = BlackScholesFormulaRepository.price( 0., strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, true); double resC2 = BlackScholesFormulaRepository.price( 1.e12 * strike, strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, true); double refC2 = BlackScholesFormulaRepository.price( inf, strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, true); double resP1 = BlackScholesFormulaRepository.price( 1.e-12 * strike, strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, false); double refP1 = BlackScholesFormulaRepository.price( 0., strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, false); double resP2 = BlackScholesFormulaRepository.price( 1.e12 * strike, strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, false); double refP2 = BlackScholesFormulaRepository.price( inf, strike, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, false); double rate = INTEREST_RATES[l]; double vol = VOLS[j]; double resC1 = BlackScholesFormulaRepository.price( SPOT, 1.e-12 * SPOT, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, true); double resC2 = BlackScholesFormulaRepository.price( SPOT, 1.e12 * SPOT, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, true); double resP1 = BlackScholesFormulaRepository.price( SPOT, 1.e-12 * SPOT, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, false); double resP2 = BlackScholesFormulaRepository.price( SPOT, 1.e12 * SPOT, TIME_TO_EXPIRY, vol, rate, COST_OF_CARRY, false);
public void test_trinomialTree() { int nSteps = 135; LatticeSpecification[] lattices = new LatticeSpecification[] {new CoxRossRubinsteinLatticeSpecification(), new TrigeorgisLatticeSpecification() }; double tol = 5.0e-3; for (boolean isCall : new boolean[] {true, false }) { for (double strike : STRIKES) { for (double interest : INTERESTS) { for (double vol : VOLS) { for (double dividend : DIVIDENDS) { OptionFunction function = EuropeanVanillaOptionFunction.of(strike, TIME, PutCall.ofPut(!isCall), nSteps); double exact = BlackScholesFormulaRepository.price(SPOT, strike, TIME, vol, interest, interest - dividend, isCall); for (LatticeSpecification lattice : lattices) { double computed = TRINOMIAL_TREE.optionPrice(function, lattice, SPOT, vol, interest, dividend); assertEquals(computed, exact, Math.max(exact, 1d) * tol); } } } } } } }
double finDeltaC = (BlackScholesFormulaRepository.price( upSpot, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true) - BlackScholesFormulaRepository.price( dwSpot, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true)) / 2. / SPOT / DELTA; double finDeltaP = (BlackScholesFormulaRepository.price( upSpot, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, false) - BlackScholesFormulaRepository.price( dwSpot, STRIKES_INPUT[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, false)) / 2. / SPOT / DELTA; double finDualDeltaC = (BlackScholesFormulaRepository.price( SPOT, upStrikes[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true) - BlackScholesFormulaRepository.price( SPOT, dwStrikes[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true)) / 2. / STRIKES_INPUT[i] / DELTA; double finDualDeltaP = (BlackScholesFormulaRepository.price( SPOT, upStrikes[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, false) - BlackScholesFormulaRepository.price( SPOT, dwStrikes[i], TIME_TO_EXPIRY, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, false)) / 2. / STRIKES_INPUT[i] / DELTA; double finThetaC = -(BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[i], upTime, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true) - BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[i], dwTime, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, true)) / 2. / TIME_TO_EXPIRY / DELTA; double finThetaP = -(BlackScholesFormulaRepository.price( SPOT, STRIKES_INPUT[i], upTime, VOLS[j], INTEREST_RATES[k], COST_OF_CARRY, false) -