Package com.opengamma.analytics.financial.model.finitedifference

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


      //call option with low strike  is worth the forward - strike, while a put is worthless
      lower = new DirichletBoundaryCondition((1.0 - minMoneyness), minMoneyness);
      upper = new DirichletBoundaryCondition(0.0, maxMoneyness);
    } else {
      lower = new DirichletBoundaryCondition(0.0, minMoneyness);
      upper = new NeumannBoundaryCondition(1.0, maxMoneyness, false);
    }
    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> initialCond = (new InitialConditionsProvider()).getForwardCallPut(isCall);
View Full Code Here


    return option.isCall() ? new DirichletBoundaryCondition(0, 0) : new DirichletBoundaryCondition(strike, 0);
  }

  private BoundaryCondition getUpperBoundaryCondition(final EuropeanVanillaOption option, final double maxForward) {
    //call option with strike zero is worth the forward, while a put is worthless
    return option.isCall() ? new NeumannBoundaryCondition(1.0, maxForward, false) : new NeumannBoundaryCondition(0.0, maxForward, false);
  }
View Full Code Here

    return option.isCall() ? new DirichletBoundaryCondition(1.0 - minMoneyness, minMoneyness) : new DirichletBoundaryCondition(0.0, minMoneyness);
  }

  private BoundaryCondition getUpperBoundaryCondition(final EuropeanVanillaOption option, final double maxMoneyness) {
    //call option with strike zero is worth the forward, while a put is worthless
    return option.isCall() ? new DirichletBoundaryCondition(0.0, maxMoneyness) : new NeumannBoundaryCondition(1.0, maxMoneyness, false);
  }
View Full Code Here

    final BoundaryCondition lower1 = new DirichletBoundaryCondition(strikeZeroPrice1, 0.0);
    final BoundaryCondition lower2 = new DirichletBoundaryCondition(strikeZeroPrice2, 0.0);

    final double kMax = grid.getSpaceNode(grid.getNumSpaceNodes() - 1);

    final BoundaryCondition upper = new NeumannBoundaryCondition(0, kMax, false);

    final CoupledPDEDataBundle d1 = new CoupledPDEDataBundle(_data[0], _initalCond1, lower1, upper, grid);
    final CoupledPDEDataBundle d2 = new CoupledPDEDataBundle(_data[1], _initalCond2, lower2, upper, grid);

    final CoupledFiniteDifference solver = new CoupledFiniteDifference(theta, true);
View Full Code Here

    PDEResults1D res;

    if (isAmerican) {
      if (isCall) {
        lower = new NeumannBoundaryCondition(0.0, sMin, true);
        upper = new NeumannBoundaryCondition(1.0, sMax, false);
      } else {
        lower = new NeumannBoundaryCondition(-1.0, sMin, true);
        upper = new NeumannBoundaryCondition(0.0, sMax, false);
      }

      final Function<Double, Double> func = new Function<Double, Double>() {
        @Override
        public Double evaluate(final Double... tx) {
          final double x = tx[1];
          return payoff.evaluate(x);
        }
      };

      final FunctionalDoublesSurface free = new FunctionalDoublesSurface(func);

      PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, free, grid[0]);
      ThetaMethodFiniteDifference solver = new ThetaMethodFiniteDifference(theta[0], false);
      res = solver.solve(data);
      for (int ii = 1; ii < n; ii++) {
        data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, res.getTerminalResults(), lower, upper, free, grid[ii]);
        solver = new ThetaMethodFiniteDifference(theta[ii], false);
        res = solver.solve(data);
      }
      // European
    } else {
      if (isCall) {
        lower = new NeumannBoundaryCondition(0.0, sMin, true);
        final Function1D<Double, Double> upFunc = new Function1D<Double, Double>() {
          @Override
          public Double evaluate(final Double time) {
            return Math.exp(-q * time);
          }
        };
        upper = new NeumannBoundaryCondition(upFunc, sMax, false);
      } else {
        final Function1D<Double, Double> downFunc = new Function1D<Double, Double>() {
          @Override
          public Double evaluate(final Double time) {
            return -Math.exp(-q * time);
          }
        };
        lower = new NeumannBoundaryCondition(downFunc, sMin, true);
        upper = new NeumannBoundaryCondition(0.0, sMax, false);
      }
      PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, grid[0]);
      ThetaMethodFiniteDifference solver = new ThetaMethodFiniteDifference(theta[0], false);
      res = solver.solve(data);
      for (int ii = 1; ii < n; ii++) {
View Full Code Here

    _data2 = getExtendedCoupledPDEDataBundle(forward, data.getVol2(), data.getLambda21(), data.getLambda12(), 1.0 - data.getP0(), data.getBeta2(), localVolOverlay);
  }

  PDEFullResults1D[] solve(final PDEGrid1D grid) {

    final BoundaryCondition lower = new NeumannBoundaryCondition(0.0, grid.getSpaceNode(0), true);
    //BoundaryCondition lower = new DirichletBoundaryCondition(0.0, 0.0);//TODO for beta < 0.5 zero is accessible and thus there will be non-zero
    //density there
    final BoundaryCondition upper = new DirichletBoundaryCondition(0.0, grid.getSpaceNode(grid.getNumSpaceNodes() - 1));

    final ExtendedCoupledFiniteDifference solver = new ExtendedCoupledFiniteDifference(THETA);
View Full Code Here

    PDEResults1D res;

    if (isAmerican) {
      if (isCall) {
        lower = new NeumannBoundaryCondition(0.0, sMin, true);
        upper = new NeumannBoundaryCondition(1.0, sMax, false);
      } else {
        lower = new NeumannBoundaryCondition(-1.0, sMin, true);
        upper = new NeumannBoundaryCondition(0.0, sMax, false);
      }

      final Function<Double, Double> func = new Function<Double, Double>() {
        @Override
        public Double evaluate(Double... tx) {
          final double x = tx[1];
          return isCall ? Math.max(x - k, 0.0) : Math.max(k - x, 0);
        }
      };

      final FunctionalDoublesSurface free = new FunctionalDoublesSurface(func);
      if (USE_BURNIN) {
        PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> dataBurn = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, free, gridBurn);
        PDEResults1D resBurn = INITIAL_SOLVER.solve(dataBurn);

        PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, resBurn.getTerminalResults(), lower, upper, free, grid);
        res = SOLVER.solve(data);
      } else {
        PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, free, grid);
        res = SOLVER.solve(data);
      }

    } else {
      if (isCall) {
        lower = new NeumannBoundaryCondition(0.0, sMin, true);
        Function1D<Double, Double> upFunc = new Function1D<Double, Double>() {
          @Override
          public Double evaluate(Double time) {
            return Math.exp(-q * time);
          }
        };
        upper = new NeumannBoundaryCondition(upFunc, sMax, false);
      } else {
        Function1D<Double, Double> downFunc = new Function1D<Double, Double>() {
          @Override
          public Double evaluate(Double time) {
            return -Math.exp(-q * time);
          }
        };
        lower = new NeumannBoundaryCondition(downFunc, sMin, true);
        upper = new NeumannBoundaryCondition(0.0, sMax, false);
      }
      if (USE_BURNIN) {
        PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> dataBurn = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, gridBurn);
        PDEResults1D resBurn = INITIAL_SOLVER.solve(dataBurn);

View Full Code Here

  }

  PDEFullResults1D[] solve(final PDEGrid1D grid) {

    //BoundaryCondition lower = new FixedSecondDerivativeBoundaryCondition(0, grid.getSpaceNode(0), true);
    final BoundaryCondition lower = new NeumannBoundaryCondition(0.0, grid.getSpaceNode(0), true);
    //BoundaryCondition lower = new DirichletBoundaryCondition(0.0, grid.getSpaceNode(0));//TODO for beta < 0.5 zero is accessible and thus there will be non-zero
    //density there
    final BoundaryCondition upper = new DirichletBoundaryCondition(0.0, grid.getSpaceNode(grid.getNumSpaceNodes() - 1));

    CoupledPDEDataBundle d1 = new CoupledPDEDataBundle(_data1, _initCon11, lower, upper, grid);
View Full Code Here

    PDEResults1D res;

    if (isAmerican) {
      if (option.isCall()) {
        lower = new NeumannBoundaryCondition(0.0, sMin, true);
        upper = new NeumannBoundaryCondition(1.0, sMax, false);
      } else {
        lower = new NeumannBoundaryCondition(-1.0, sMin, true);
        upper = new NeumannBoundaryCondition(0.0, sMax, false);
      }

      final Function<Double, Double> func = new Function<Double, Double>() {
        @Override
        public Double evaluate(final Double... tx) {
          final double x = tx[1];
          return payoff.evaluate(x);
        }
      };

      final FunctionalDoublesSurface free = new FunctionalDoublesSurface(func);

      PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, free, grid[0]);
      ThetaMethodFiniteDifference solver = new ThetaMethodFiniteDifference(theta[0], false);
      res = solver.solve(data);
      for (int ii = 1; ii < n; ii++) {
        data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, res.getTerminalResults(), lower, upper, free, grid[ii]);
        solver = new ThetaMethodFiniteDifference(theta[ii], false);
        res = solver.solve(data);
      }
      // European
    } else {
      if (option.isCall()) {
        lower = new NeumannBoundaryCondition(0.0, sMin, true);
        final Function1D<Double, Double> upFunc = new Function1D<Double, Double>() {
          @Override
          public Double evaluate(final Double tau) {
            return Math.exp((costOfCarry.getYValue(tau) - riskFreeRate.getYValue(tau)) * tau);
          }
        };
        upper = new NeumannBoundaryCondition(upFunc, sMax, false);
      } else {
        final Function1D<Double, Double> downFunc = new Function1D<Double, Double>() {
          @Override
          public Double evaluate(final Double tau) {
            return -Math.exp((costOfCarry.getYValue(tau) - riskFreeRate.getYValue(tau)) * tau);
          }
        };
        lower = new NeumannBoundaryCondition(downFunc, sMin, true);
        upper = new NeumannBoundaryCondition(0.0, sMax, false);
      }
      PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, grid[0]);
      ThetaMethodFiniteDifference solver = new ThetaMethodFiniteDifference(theta[0], false);
      res = solver.solve(data);
      for (int ii = 1; ii < n; ii++) {
View Full Code Here

    //common boundary conditions
    //TODO the grid involves some magic numbers that should be possible to alter externally by expert users
    final double xL = 0.0;
    final double xH = 6;
    final BoundaryCondition lower = new DirichletBoundaryCondition(1.0, xL);
    final BoundaryCondition upper = new NeumannBoundaryCondition(0.0, xH, false);
    final MeshingFunction spaceMesh = new HyperbolicMeshing(xL, xH, 1.0, _nSpaceSteps + 1, 0.001); //0.05
    final MeshingFunction[] timeMeshes = new MeshingFunction[nDivsBeforeExpiry + 1];
    final PDEGrid1D[] grids = new PDEGrid1D[nDivsBeforeExpiry + 1];
    if (nDivsBeforeExpiry == 0) {
      timeMeshes[0] = new ExponentialMeshing(0, expiry, _nTimeSteps, 5.0);
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.model.finitedifference.NeumannBoundaryCondition

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.