Package com.opengamma.analytics.financial.model.volatility.surface

Examples of com.opengamma.analytics.financial.model.volatility.surface.BlackVolatilitySurfaceMoneyness


        for (int i = 0; i < nWeights; i++) {
          weights[i] = TRANSFORM.inverseTransform(x.getEntry(i));
        }

        final LocalVolatilitySurfaceMoneyness localVolSurface = getLocalVol(bSplines, fwdCurve, weights);
        final BlackVolatilitySurfaceMoneyness impVol = solveForwardPDE(fwdCurve, lower, upper, pdeGrid, initialCond, localVolSurface);

        final double[] vols = new double[totalStrikes];
        @SuppressWarnings("unused")
        double chi2 = 0;
        int index = 0;
        for (int i = 0; i < nExp; i++) {
          final double t = EXPIRIES[i];
          final int n = STRIKES[i].length;
          for (int j = 0; j < n; j++) {
            final double k = STRIKES[i][j];
            vols[index] = impVol.getVolatility(t, k);
            chi2 += FunctionUtils.square(vols[index] - IMP_VOL);
            index++;
          }
        }
        final DoubleMatrix1D debug = new DoubleMatrix1D(vols);
        //  System.out.println(chi2);
        return debug;
      }

    };

    final double[] start = new double[nWeights];
    // Arrays.fill(start, 0.4);
    for (int i = 0; i < nWeights; i++) {
      start[i] = TRANSFORM.transform(IMP_VOL + 0.05 * (random.nextDouble() - 0.5));
    }

    //  DoubleMatrix1D res = MINIMIZER.minimize(objective, new DoubleMatrix1D(start));
    final DoubleMatrix1D observed = new DoubleMatrix1D(totalStrikes, IMP_VOL);
    final LeastSquareResults res = NLLS.solve(observed, volFunc, new DoubleMatrix1D(start), penalty);
    System.out.println(res);

    final double[] weights = new double[nWeights];
    for (int i = 0; i < nWeights; i++) {
      weights[i] = TRANSFORM.inverseTransform(res.getFitParameters().getEntry(i));
    }

    final LocalVolatilitySurfaceMoneyness lv = getLocalVol(bSplines, fwdCurve, weights);
    PDEUtilityTools.printSurface("lv", lv.getSurface(), 0.01, 2.0, 0.3, 3.0);

    final BlackVolatilitySurfaceMoneyness iv = solveForwardPDE(fwdCurve, lower, upper, pdeGrid, initialCond, lv);
    PDEUtilityTools.printSurface("imp vol", iv.getSurface(), 0.01, 2.0, 0.3, 3.0);
  }
View Full Code Here


          weights[i] = TRANSFORM.inverseTransform(x.getEntry(i));
        }

        final LocalVolatilitySurfaceMoneyness localVolSurface = getLocalVol1D(bSplines, fwdCurve, weights);

        final BlackVolatilitySurfaceMoneyness impVol = solveForwardPDE(fwdCurve, lower, upper, pdeGrid, initialCond, localVolSurface);

        final double[] vols = new double[totalStrikes];
        @SuppressWarnings("unused")
        double chi2 = 0;
        int index = 0;
        for (int i = 0; i < nExp; i++) {
          final double t = EXPIRIES[i];
          final int n = STRIKES[i].length;
          for (int j = 0; j < n; j++) {
            final double k = STRIKES[i][j];
            vols[index] = impVol.getVolatility(t, k);
            chi2 += FunctionUtils.square(vols[index] - IMP_VOL);
            index++;
          }
        }
        final DoubleMatrix1D debug = new DoubleMatrix1D(vols);
View Full Code Here

        final DoublesPair data = new DoublesPair(x[0], x[1]);
        return INTERPOLATOR.interpolate(idb, data);
      }
    };

    final BlackVolatilitySurfaceMoneyness impVol = new BlackVolatilitySurfaceMoneyness(FunctionalDoublesSurface.from(f2), fwdCurve);
    return impVol;
  }
View Full Code Here

  @Test
  public void testVolatilitySurfaceInterpolator() {
    final VolatilitySurfaceInterpolator fitter = cycleObject(VolatilitySurfaceInterpolator.class, VOLATILITY_SURFACE_INTERPOLATOR);
    assertEquals(VOLATILITY_SURFACE_INTERPOLATOR.getSmileInterpolator(), fitter.getSmileInterpolator());
    assertEquals(VOLATILITY_SURFACE_INTERPOLATOR, fitter);
    final BlackVolatilitySurfaceMoneyness surface1 = VOLATILITY_SURFACE_INTERPOLATOR.getVolatilitySurface(FOREX_DATA);
    final BlackVolatilitySurfaceMoneyness surface2 = cycleObject(BlackVolatilitySurfaceMoneyness.class, surface1);
    assertEquals(surface1.getForwardCurve().getSpot(), surface2.getForwardCurve().getSpot());
    assertCurveEquals(surface1.getForwardCurve().getForwardCurve(), surface2.getForwardCurve().getForwardCurve());
    //    assertSurfaceEquals(surface1.getSurface(), surface2.getSurface());
  }
View Full Code Here

   * Print the fitted implied vol surface and the derived implied vol
   */
  @Test
      (enabled = false)
      public void printSurface() {
    final BlackVolatilitySurfaceMoneyness surface = SURFACE_FITTER.getVolatilitySurface(MARKET_DATA);
    PDEUtilityTools.printSurface("vol surface", surface.getSurface(), 0, 7. / 365, 0.95, 1.05, 200, 100);
    //    Surface<Double, Double, Double> dens = DUPIRE.getDensity(surface);
    //    PDEUtilityTools.printSurface("density surface", dens, 0.01, 1.0, 0.75, 1.25, 200, 100);
    //    Surface<Double, Double, Double> theta = DUPIRE.getTheta(surface);
    //  PDEUtilityTools.printSurface("theta surface", theta, 0, 10, 0.1, 3.0, 200, 100);
    LocalVolatilitySurfaceMoneyness lv = DUPIRE.getLocalVolatility(surface);
View Full Code Here

  @Test
      (enabled = false)
      public void printDeltaProxySurface() {
    final double xMin = -0.5;
    final double xMax = 0.5;
    final BlackVolatilitySurfaceMoneyness surface = SURFACE_FITTER.getVolatilitySurface(MARKET_DATA);
    final Surface<Double, Double, Double> moneynessSurface = toDeltaProxySurface(surface);
    PDEUtilityTools.printSurface("moneyness surface", moneynessSurface, 0, 10, xMin, xMax, 200, 100);

    //    final LocalVolatilitySurfaceMoneyness lv = DUPIRE.getLocalVolatility(surface);
    //    final Surface<Double, Double, Double> lvMoneynessSurface = toDeltaProxySurface(lv);
View Full Code Here

    final double forwardOptionPrice = spotOptionPrice * forward / spot;
   
    double impliedVol = BlackFormulaRepository.impliedVolatility(forwardOptionPrice, forward, strike, timeToExpiry, 0.3);
   
    final Surface<Double, Double, Double> surface = ConstantDoublesSurface.from(impliedVol);
    final BlackVolatilitySurfaceMoneyness impliedVolatilitySurface = new BlackVolatilitySurfaceMoneyness(surface, forwardCurve);
    final ValueProperties properties = getResultProperties(desiredValues.iterator().next());
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.BLACK_VOLATILITY_SURFACE, target.toSpecification(), properties);
    return Collections.singleton(new ComputedValue(spec, impliedVolatilitySurface));
  }
View Full Code Here

    if (interpolatorObject == null) {
      throw new OpenGammaRuntimeException("Could not get volatility surface interpolator");
    }
    final VolatilitySurfaceInterpolator surfaceInterpolator = (VolatilitySurfaceInterpolator) interpolatorObject;
    final SmileSurfaceDataBundle data = getData(inputs);
    final BlackVolatilitySurfaceMoneyness impliedVolatilitySurface = surfaceInterpolator.getVolatilitySurface(data);
    final ValueProperties properties = getResultProperties(desiredValue);
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.BLACK_VOLATILITY_SURFACE, target.toSpecification(), properties);
    return Collections.singleton(new ComputedValue(spec, impliedVolatilitySurface));
  }
View Full Code Here

    final double eps = Double.parseDouble(desiredValue.getConstraint(PROPERTY_DERIVATIVE_EPS));
    final Object impliedVolatilitySurfaceObject = inputs.getValue(getVolatilitySurfaceRequirement(target, desiredValue));
    if (impliedVolatilitySurfaceObject == null) {
      throw new OpenGammaRuntimeException("Volatility surface was null");
    }
    final BlackVolatilitySurfaceMoneyness impliedVolatilitySurface = (BlackVolatilitySurfaceMoneyness) impliedVolatilitySurfaceObject;
    final DupireLocalVolatilityCalculator calculator = new DupireLocalVolatilityCalculator(eps);
    final LocalVolatilitySurfaceMoneyness localVolatilitySurface = calculator.getLocalVolatility(impliedVolatilitySurface);
    final ValueProperties properties = getResultProperties(desiredValue, LocalVolatilitySurfacePropertyNamesAndValues.MONEYNESS);
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.LOCAL_VOLATILITY_SURFACE, target.toSpecification(), properties);
    return Collections.singleton(new ComputedValue(spec, localVolatilitySurface));
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.model.volatility.surface.BlackVolatilitySurfaceMoneyness

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.