Package com.opengamma.analytics.financial.model.option.definition

Examples of com.opengamma.analytics.financial.model.option.definition.StandardOptionDataBundle


      _price = price;
    }

    @Override
    public StandardOptionDataBundle getRoot(final Function1D<StandardOptionDataBundle, Double> function, final StandardOptionDataBundle... volData) {
      final StandardOptionDataBundle lowVolData = volData[0];
      final StandardOptionDataBundle highVolData = volData[1];
      final Double lowPrice = function.evaluate(lowVolData) - _price;
      if (Math.abs(lowPrice) < ACCURACY) {
        return lowVolData;
      }
      Double highPrice = function.evaluate(highVolData) - _price;
      if (Math.abs(highPrice) < ACCURACY) {
        return highVolData;
      }
      final double highVol = highVolData.getVolatilitySurface().getVolatility(_origin);
      final double lowVol = lowVolData.getVolatilitySurface().getVolatility(_origin);
      double dVol, midVol, rootVol;
      if (lowPrice < 0) {
        dVol = highVol - lowVol;
        rootVol = lowVol;
      } else {
        dVol = lowVol - highVol;
        rootVol = highVol;
      }
      StandardOptionDataBundle midVolData;
      for (int i = 0; i < MAX_ATTEMPTS; i++) {
        dVol *= 0.5;
        midVol = rootVol + dVol;
        midVolData = _data.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from((midVol))));
        highPrice = function.evaluate(midVolData) - _price;
View Full Code Here


        final double sigmaSq = sigma * sigma;
        double z;
        final double lambdaT = lambda * t;
        double mult = Math.exp(-lambdaT);
        b -= lambda * expectedJumpSize;
        StandardOptionDataBundle bsmData = new StandardOptionDataBundle(discountCurve, b, volSurface, s, date);
        final Function1D<StandardOptionDataBundle, Double> bsmFunction = BSM.getPricingFunction(definition);
        double price = mult * bsmFunction.evaluate(bsmData);
        for (int i = 1; i < N; i++) {
          z = Math.sqrt(sigmaSq + delta * delta * i / t);
          b += gamma / t;
          bsmData = bsmData.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(z))).withCostOfCarry(b);
          mult *= lambdaT / i;
          price += mult * bsmFunction.evaluate(bsmData);
        }
        return price;
      }
View Full Code Here

        final double b = data.getCostOfCarry();
        final double lambda = data.getHalfLife();
        final double sigmaLR = data.getLongRunVolatility();
        final double volOfSigma = data.getVolatilityOfVolatility();
        final double rho = data.getCorrelation();
        final StandardOptionDataBundle bsmData = new StandardOptionDataBundle(data);
        final OptionDefinition call = definition.isCall() ? definition : new EuropeanVanillaOptionDefinition(k, definition.getExpiry(), true);
        final double beta = -Math.log(2) / lambda;
        final double alpha = -beta * sigmaLR * sigmaLR;
        final double delta = beta * t;
        final double eDelta = Math.exp(delta);
        final boolean betaIsZero = CompareUtils.closeEquals(beta, 0, ZERO);
        final double variance = sigma * sigma;
        final double meanVariance = getMeanVariance(betaIsZero, variance, alpha, t, beta, eDelta, delta);
        final double df = getDF(r, b, t);
        final double sDf = s * df;
        final double d1 = getD(s, k, b, meanVariance, t);
        final double d2 = d1 - Math.sqrt(meanVariance * t);
        final double nD1 = NORMAL.getPDF(d1);
        final double f0 = BSM.getPricingFunction(call).evaluate(bsmData.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(Math.sqrt(meanVariance)))));
        final double f1 = getF1(betaIsZero, variance, rho, alpha, t, beta, delta, eDelta, sDf, nD1, d2, meanVariance);
        final double f2 = getF2(betaIsZero, variance, rho, alpha, t, beta, delta, eDelta, sDf, nD1, d1, d2, meanVariance);
        final double callPrice = f0 + f1 * volOfSigma + f2 * volOfSigma * volOfSigma;
        if (!definition.isCall()) {
          return callPrice - s * df + k * Math.exp(-r * t);
 
View Full Code Here

        final double z = Math.sqrt(sigmaSq - lambda * delta * delta);
        final double zSq = z * z;
        double sigmaAdjusted = z;
        final double lambdaT = lambda * t;
        double mult = Math.exp(-lambdaT);
        final StandardOptionDataBundle bsmData = new StandardOptionDataBundle(data.getInterestRateCurve(), data.getCostOfCarry(), new VolatilitySurface(ConstantDoublesSurface.from(sigmaAdjusted)),
            data.getSpot(), date);
        final Function1D<StandardOptionDataBundle, Double> bsmFunction = BSM.getPricingFunction(definition);
        double price = mult * bsmFunction.evaluate(bsmData);
        for (int i = 1; i < N; i++) {
          sigmaAdjusted = Math.sqrt(zSq + delta * delta * i / t);
          mult *= lambdaT / i;
          price += mult * bsmFunction.evaluate(bsmData.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(sigmaAdjusted))));
        }
        return price;
      }
    };
    return pricingFunction;
View Full Code Here

      final double price = res.getFunctionValue(i);
      final double delta = res.getFirstSpatialDerivative(i);
      final double gamma = res.getSecondSpatialDerivative(i);
      final double moneyness = spot / OPTION.getStrike();

      final StandardOptionDataBundle standOptData = new StandardOptionDataBundle(YIELD_CURVE, RATE, VOL_SURFACE, spot, DATE);
      final GreekResultCollection greekResults = BS_MODEL.getGreeks(OPTION_DEFINITION, standOptData, GREEKS);

      final BlackFunctionData data = new BlackFunctionData(spot / df, df, ATM_VOL);

      double impVol;
View Full Code Here

      final double price = 2.0 * res2.getFunctionValue(i) - res1.getFunctionValue(i);
      final double delta = 2.0 * res2.getFirstSpatialDerivative(i) - res1.getFirstSpatialDerivative(i);
      final double gamma = 2.0 * res2.getSecondSpatialDerivative(i) - res1.getSecondSpatialDerivative(i);
      final double moneyness = spot / OPTION.getStrike();

      final StandardOptionDataBundle standOptData = new StandardOptionDataBundle(YIELD_CURVE, RATE, VOL_SURFACE, spot, DATE);
      final GreekResultCollection greekResults = BS_MODEL.getGreeks(OPTION_DEFINITION, standOptData, GREEKS);

      final BlackFunctionData data = new BlackFunctionData(spot / df, df, ATM_VOL);

      double impVol;
View Full Code Here

      final double price = res.getFunctionValue(i);
      final double delta = res.getFirstSpatialDerivative(i) / spot;
      final double gamma = (res.getSecondSpatialDerivative(i) / spot - delta) / spot;
      final double moneyness = spot / OPTION.getStrike();

      final StandardOptionDataBundle standOptData = new StandardOptionDataBundle(YIELD_CURVE, RATE, VOL_SURFACE, spot, DATE);
      final GreekResultCollection greekResults = BS_MODEL.getGreeks(OPTION_DEFINITION, standOptData, GREEKS);

      final BlackFunctionData data = new BlackFunctionData(spot / df, df, ATM_VOL);

      double impVol;
View Full Code Here

      final double spot = res.getSpaceValue(i);
      final double price = res.getFunctionValue(i);
      final double delta = res.getFirstSpatialDerivative(i);
      final double gamma = res.getSecondSpatialDerivative(i);
      final double moneyness = spot / OPTION.getStrike();
      final StandardOptionDataBundle dataBundle = new StandardOptionDataBundle(YIELD_CURVE, RATE, VOL_SURFACE, spot, DATE);
      final Double anal_price = pFunc.evaluate(dataBundle);
      if (print) {
        System.out.println(spot + "\t" + anal_price + "\t" + price + "\t" + delta + "\t" + gamma);
      } else {
        if (moneyness >= lowerMoneyness && moneyness <= upperMoneyness) {
View Full Code Here

    boolean isCall;
    double spot, strike, b, price;
    Expiry expiry;
    YieldAndDiscountCurve curve;
    EuropeanVanillaOptionDefinition definition;
    StandardOptionDataBundle initialData, data;
    double sigma = 0.01;
    for (int i = 0; i < 100; i++) {
      expiry = new Expiry(DateUtils.getDateOffsetWithYearFraction(DATE, RANDOM.nextDouble() * 2));
      sigma += 0.03;
      spot = 2 * RANDOM.nextDouble() + 10;
      strike = 2 * RANDOM.nextDouble() + 10;
      curve = YieldCurve.from(ConstantDoublesCurve.from(RANDOM.nextDouble() / 10));
      b = 0;//RANDOM.nextDouble() / 20;
      isCall = RANDOM.nextDouble() < 0.5 ? true : false;
      definition = new EuropeanVanillaOptionDefinition(strike, expiry, isCall);
      initialData = new StandardOptionDataBundle(curve, b, null, spot, DATE);
      data = new StandardOptionDataBundle(curve, b, new VolatilitySurface(ConstantDoublesSurface.from(sigma)), spot, DATE);
      price = BSM.getPricingFunction(definition).evaluate(data);
      assertEquals(sigma, MODEL.getSurface(Collections.<OptionDefinition, Double> singletonMap(definition, price), initialData).getVolatility(DoublesPair.of(0., 0.)), EPS);
    }
  }
View Full Code Here

    final YieldAndDiscountCurve discountCurve = (YieldAndDiscountCurve) inputs.getValue(discountCurveDataRequirement);
    final double spotPrice = (Double) inputs.getValue(underlyingPriceRequirement);
    final Expiry expiry = option.getExpiry();
    final double t = DateUtils.getDifferenceInYears(now, expiry.getExpiry());
    final double b = discountCurve.getInterestRate(t); // TODO cost-of-carry model
    @SuppressWarnings("unused")
    final StandardOptionDataBundle data = new StandardOptionDataBundle(discountCurve, b, null, spotPrice, now);
    // TODO Map<OptionDefinition, Double> of options that will be used to form surface
    final VolatilitySurface surface = null; // TODO
    final ValueSpecification specification = createResultSpecification(target);
    final ComputedValue result = new ComputedValue(specification, surface);
    return Collections.singleton(result);
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.model.option.definition.StandardOptionDataBundle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.