Examples of PDEFullResults1D


Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    final PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db1 = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(pde1, initalCondition, lower, upper, grid);
    final PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db2 = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(pde2, initalCondition, lower, upper, grid);

    final ThetaMethodFiniteDifference thetaMethod = new ThetaMethodFiniteDifference(0.5, true);

    final PDEFullResults1D res1 = (PDEFullResults1D) thetaMethod.solve(db1);
    final PDEFullResults1D res2 = (PDEFullResults1D) thetaMethod.solve(db2);

    PDEUtilityTools.printSurface("State 1 density", res1);
    PDEUtilityTools.printSurface("State 2 density", res2);
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    @Override
    public PDEFullResults1D buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
      final double[][] solverData = deserializer.fieldValueToObject(double[][].class, message.getByName(SOLVER_DATA_FIELD));
      final PDEGrid1D grid = deserializer.fieldValueToObject(PDEGrid1D.class, message.getByName(GRID_FIELD));
      return new PDEFullResults1D(grid, solverData);
    }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    final double[][] strikes = _marketData.getStrikes();
    final double[][] vols = _marketData.getVolatilities();
    final double maxT = expiries[n - 1];
    final double maxProxyDelta = 0.4;

    final PDEFullResults1D pdeRes = runForwardPDESolver(_localVolatilityMoneyness, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final BlackVolatilitySurfaceMoneyness pdeVolSurface = modifiedPriceToVolSurface(_marketData.getForwardCurve(), pdeRes, 0, maxT, 0.3, 3.0, _isCall);
    double chiSq = 0;
    for (int i = 0; i < n; i++) {
      final int m = strikes[i].length;
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

      if (d > maxProxyDelta) {
        maxProxyDelta = d;
      }
    }

    final PDEFullResults1D pdeRes = runForwardPDESolver(forwardCurve, localVol, _isCall, _theta, expiry, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final int n = pdeRes.getNumberSpaceNodes();
    double[] logM = new double[n];
    double[] impVol = new double[n];
    int count = 0;

    for (int i = 0; i < n; i++) {
      final double m = pdeRes.getSpaceValue(i);
      if (m > 0.3 && m < 3.0) {
        final double mPrice = pdeRes.getFunctionValue(i);
        try {
          impVol[count] = BlackFormulaRepository.impliedVolatility(mPrice, 1.0, m, expiry, _isCall);
          logM[count] = Math.log(m);
          count++;
        } catch (final Exception e) {
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    final double shift = 1e-2;

    final double maxForward = 3.5 * forward;
    final double maxProxyDelta = 1.5;

    final PDEFullResults1D pdeRes = runForwardPDESolver(forwardCurve, localVol, _isCall, _theta, expiry, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEFullResults1D pdeResUp = runForwardPDESolver(forwardCurve.withFractionalShift(shift), localVol, _isCall, _theta, expiry, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEFullResults1D pdeResDown = runForwardPDESolver(forwardCurve.withFractionalShift(-shift), localVol, _isCall, _theta, expiry, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);

    final int n = pdeRes.getNumberSpaceNodes();

    ps.println("Result of running Forward PDE solver - this gives you a grid of prices at expiries and strikes for a spot " +
        "and forward curve. Dual delta and gamma are calculated by finite difference on the PDE grid. Spot delta and " +
        "gamma are calculated by ");
    ps.println("Strike\tVol\tBS Delta\tDelta\tBS Dual Delta\tDual Delta\tBS Gamma\tGamma\tBS Dual Gamma\tDual Gamma");
    //\tsurface delta\tsurface gamma\t surface cross gamma\tmodel dg");

    final double minM = Math.exp(-1.0 * Math.sqrt(expiry));
    final double maxM = 1.0 / minM;
    for (int i = 0; i < n; i++) {
      final double m = pdeRes.getSpaceValue(i);
      if (m > minM && maxM < 3.0) {
        final double k = m * forward;

        final double mPrice = pdeRes.getFunctionValue(i);
        double impVol = 0;
        try {
          impVol = BlackFormulaRepository.impliedVolatility(mPrice, 1.0, m, expiry, _isCall);
        } catch (final Exception e) {
        }

        final double bsDelta = BlackFormulaRepository.delta(forward, k, expiry, impVol, _isCall);
        final double bsDualDelta = BlackFormulaRepository.dualDelta(forward, k, expiry, impVol, _isCall);
        final double bsGamma = BlackFormulaRepository.gamma(forward, k, expiry, impVol);
        final double bsDualGamma = BlackFormulaRepository.dualGamma(forward, k, expiry, impVol);

        final double modelDD = pdeRes.getFirstSpatialDerivative(i);
        final double fixedSurfaceDelta = mPrice - m * modelDD; //i.e. the delta if the moneyness parameterised local vol surface was invariant to forward
        final double surfaceDelta = (pdeResUp.getFunctionValue(i) - pdeResDown.getFunctionValue(i)) / 2 / forward / shift;
        final double modelDelta = fixedSurfaceDelta + forward * surfaceDelta;

        final double modelDG = pdeRes.getSecondSpatialDerivative(i) / forward;
        final double crossGamma = (pdeResUp.getFirstSpatialDerivative(i) - pdeResDown.getFirstSpatialDerivative(i)) / 2 / forward / shift;
        final double surfaceGamma = (pdeResUp.getFunctionValue(i) + pdeResDown.getFunctionValue(i) - 2 * pdeRes.getFunctionValue(i)) / forward / shift / shift;
        final double modelGamma = 2 * surfaceDelta + surfaceGamma - 2 * m * crossGamma + m * m * modelDG;

        ps.println(k + "\t" + impVol + "\t" + bsDelta + "\t" + modelDelta + "\t" + bsDualDelta + "\t" + modelDD
            + "\t" + bsGamma + "\t" + modelGamma + "\t" + bsDualGamma + "\t" + modelDG);
        //  + "\t" + 2 * surfaceDelta + "\t" + surfaceGamma + "\t" + -2 * m * crossGamma + "\t" + m * m *  modelDG);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    final double forward = forwardCurve.getForward(expiry);

    final double maxProxyDelta = 0.4;

    final PDEFullResults1D pdeRes = runForwardPDESolver(forwardCurve, localVol, _isCall, _theta, expiry, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);

    final int n = pdeRes.getNumberSpaceNodes();

    ps.println("Strike\tVol");

    for (int i = 0; i < n; i++) {
      final double m = pdeRes.getSpaceValue(i);
      if (m > 0.3 && m < 3.0) {
        final double k = m * forward;

        final double mPrice = pdeRes.getFunctionValue(i);
        double impVol = 0;
        try {
          impVol = BlackFormulaRepository.impliedVolatility(mPrice, 1.0, m, expiry, _isCall);
        } catch (final Exception e) {
        }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    final double forward = _marketData.getForwardCurve().getForward(option.getTimeToExpiry());
    final double maxT = option.getTimeToExpiry();
    final double maxProxyDelta = 0.4;
    final double x = option.getStrike() / forward;

    final PDEFullResults1D pdeRes = runForwardPDESolver(_localVolatilityMoneyness, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);

    final double[] xNodes = pdeRes.getGrid().getSpaceNodes();
    int index = getLowerBoundIndex(xNodes, x);
    if (index >= 1) {
      index--;
    }
    if (index >= _spaceSteps - 1) {
      index--;
      if (index >= _spaceSteps - 1) {
        index--;
      }
    }
    final double[] vols = new double[4];
    final double[] moneyness = new double[4];
    System.arraycopy(xNodes, index, moneyness, 0, 4);
    for (int i = 0; i < 4; i++) {
      vols[i] = BlackFormulaRepository.impliedVolatility(pdeRes.getFunctionValue(index + i), 1.0, moneyness[i],
          option.getTimeToExpiry(), option.isCall());
    }
    Interpolator1DDoubleQuadraticDataBundle db = INTERPOLATOR_1D.getDataBundle(moneyness, vols);
    final double exampleVol = INTERPOLATOR_1D.interpolate(db, x);

    final double shiftAmount = 1e-4; //1bps

    final double[][] res = new double[n][];

    for (int i = 0; i < n; i++) {
      final int m = strikes[i].length;
      res[i] = new double[m];
      for (int j = 0; j < m; j++) {
        final BlackVolatilitySurfaceMoneyness bumpedSurface = _surfaceFitter.getBumpedVolatilitySurface(_marketData, i, j, shiftAmount);
        final LocalVolatilitySurfaceMoneyness bumpedLV = DUPIRE.getLocalVolatility(bumpedSurface);
        final PDEFullResults1D pdeResBumped = runForwardPDESolver(bumpedLV, _isCall, _theta, maxT, maxProxyDelta,
            _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
        for (int k = 0; k < 4; k++) {
          vols[k] = BlackFormulaRepository.impliedVolatility(pdeResBumped.getFunctionValue(index + k), 1.0, moneyness[k],
              option.getTimeToExpiry(), option.isCall());
        }
        db = INTERPOLATOR_1D.getDataBundle(moneyness, vols);
        final double vol = INTERPOLATOR_1D.interpolate(db, x);
        res[i][j] = (vol - exampleVol) / shiftAmount;
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    //parallel shift the strike parameterised local vol surface
    final LocalVolatilitySurfaceStrike lvUp = new LocalVolatilitySurfaceStrike(SurfaceShiftFunctionFactory.getShiftedSurface(localVol.getSurface(), volShift, true));
    final LocalVolatilitySurfaceStrike lvDown = new LocalVolatilitySurfaceStrike(SurfaceShiftFunctionFactory.getShiftedSurface(localVol.getSurface(), -volShift, true));

    //first order shifts
    final PDEFullResults1D pdeRes = runForwardPDESolver(forwardCurve, localVol, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEResults1D pdeResUp = runForwardPDESolver(forwardCurve, lvUp, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEResults1D pdeResDown = runForwardPDESolver(forwardCurve, lvDown, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);

    //second order shifts
    final PDEResults1D pdeResUpUp = runForwardPDESolver(forwardCurve.withFractionalShift(fwdShift), lvUp, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEFullResults1D pdeResUpDown = runForwardPDESolver(forwardCurve.withFractionalShift(fwdShift), lvDown, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEFullResults1D pdeResDownUp = runForwardPDESolver(forwardCurve.withFractionalShift(-fwdShift), lvUp, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);
    final PDEFullResults1D pdeResDownDown = runForwardPDESolver(forwardCurve.withFractionalShift(-fwdShift), lvDown, _isCall, _theta, maxT, maxProxyDelta,
        _timeSteps, _spaceSteps, _timeGridBunching, _spaceGridBunching, 1.0);

    ps.println("Strike\tBS Vega\tVega\tBS Vanna\tVanna\tBS Vomma\tVomma");
    final int n = pdeRes.getNumberSpaceNodes();
    for (int i = 0; i < n; i++) {
      final double x = pdeRes.getSpaceValue(i);
      final double k = x * forward;
      final double mPrice = pdeRes.getFunctionValue(i);
      try {
        final double bsVol = BlackFormulaRepository.impliedVolatility(mPrice, 1.0, x, maxT, _isCall);
        final double bsVega = BlackFormulaRepository.vega(forward, k, maxT, bsVol);
        final double bsVanna = BlackFormulaRepository.vanna(forward, k, maxT, bsVol);
        final double bsVomma = BlackFormulaRepository.vomma(forward, k, maxT, bsVol);
        final double modelVega = forward * (pdeResUp.getFunctionValue(i) - pdeResDown.getFunctionValue(i)) / 2 / volShift;

        //xVanna is the vanna if the moneyness parameterised local vol surface was invariant to changes in the forward curve
        final double xVanna = (pdeResUp.getFunctionValue(i) - pdeResDown.getFunctionValue(i)
            - x * (pdeResUp.getFirstSpatialDerivative(i) - pdeResDown.getFirstSpatialDerivative(i))) / 2 / volShift;
        //this is the vanna coming purely from deformation of the local volatility surface
        final double surfaceVanna = (pdeResUpUp.getFunctionValue(i) + pdeResDownDown.getFunctionValue(i) -
            pdeResUpDown.getFunctionValue(i) - pdeResDownUp.getFunctionValue(i)) / 4 / fwdShift / volShift;
        final double modelVanna = xVanna + surfaceVanna;
        final double modelVomma = forward * (pdeResUp.getFunctionValue(i) + pdeResDown.getFunctionValue(i)
            - 2 * pdeRes.getFunctionValue(i)) / volShift / volShift;
        ps.println(k + "\t" + bsVega + "\t" + modelVega + "\t" + bsVanna + "\t" + modelVanna + "\t" + bsVomma + "\t" + modelVomma);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

    final MeshingFunction timeMesh = new ExponentialMeshing(0.0, maxT, nTimeSteps, timeMeshLambda);

    final MeshingFunction spaceMesh = new HyperbolicMeshing(minMoneyness, maxMoneyness, centreMoneyness, nStrikeSteps, strikeMeshBunching);
    final PDEGrid1D grid = new PDEGrid1D(timeMesh, spaceMesh);
    final Function1D<Double, Double> intCond = (new InitialConditionsProvider()).getForwardCallPut(isCall);
    final PDEFullResults1D res = (PDEFullResults1D) solver.solve(new PDE1DDataBundle<>(pde, intCond, lower, upper, grid));
    return res;
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D

  private BlackVolatilitySurfaceMoneyness solveForwardPDE(final ForwardCurve fwdCurve, final BoundaryCondition lower, final BoundaryCondition upper, final PDEGrid1D pdeGrid,
      final Function1D<Double, Double> initialCond, final LocalVolatilitySurfaceMoneyness localVolSurface) {
    final ConvectionDiffusionPDE1DStandardCoefficients pde = PDE_PROVIDER.getForwardLocalVol(localVolSurface);

    final PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(pde, initialCond, lower, upper, pdeGrid);
    final PDEFullResults1D res = (PDEFullResults1D) SOLVER.solve(db);
    final Map<DoublesPair, Double> volsurf = PDEUtilityTools.modifiedPriceToImpliedVol(res, 0.1, 2.0, 0.3, 3.0, true);

    final Map<Double, Interpolator1DDataBundle> idb = INTERPOLATOR.getDataBundle(volsurf);
    final Function<Double, Double> f2 = new Function<Double, Double>() {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.