Examples of BjerksundStenslandModel


Examples of com.opengamma.analytics.financial.model.option.pricing.analytic.BjerksundStenslandModel

  }

  public void testAmericanPrice(final ConvectionDiffusionPDESolver solver, final int timeSteps, final int priceSteps, final double lowerMoneyness, final double upperMoneyness, final boolean print) {

    final AmericanVanillaOptionDefinition option = new AmericanVanillaOptionDefinition(FORWARD, new Expiry(DateUtils.getDateOffsetWithYearFraction(DATE, T)), false);
    final BjerksundStenslandModel model = new BjerksundStenslandModel();
    final Function1D<StandardOptionDataBundle, Double> pFunc = model.getPricingFunction(option);

    final PDEGrid1D grid = new PDEGrid1D(timeSteps + 1, priceSteps + 1, T, LOWER.getLevel(), UPPER.getLevel());
    final PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(DATA, PAYOFF, LOWER, UPPER, EARLY_EXCISE, grid);

    final PDEResults1D res = solver.solve(db);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.option.pricing.analytic.BjerksundStenslandModel

      throw new OpenGammaRuntimeException("Cannot handle surface quote type " + surfaceQuoteType);
    }
    // exercise type
    //TODO REVIEW emcleod 9-7-2013 why is this not using specification.getExerciseType() instanceof AmericanExerciseType?
    final boolean isAmerican = (specification.getExerciseType()).getName().startsWith("A");
    BjerksundStenslandModel americanModel = null;
    final double spot = forwardCurve.getSpot();
    if (isAmerican) {
      americanModel = new BjerksundStenslandModel();
    }
    // Main loop: Remove empties, convert expiries from number to years, and imply vols
    final Map<Pair<Double, Double>, Double> volValues = new HashMap<>();
    final DoubleArrayList tList = new DoubleArrayList();
    final DoubleArrayList kList = new DoubleArrayList();
    final Object[] xs = rawSurface.getXs();
    for (final Object x : xs) {
      Double t;
      if (x instanceof Number) {
        t = FutureOptionExpiries.EQUITY.getFutureOptionTtm(((Number) x).intValue(), valDate);
      } else if (x instanceof LocalDate) {
        t = TimeCalculator.getTimeBetween((LocalDate) x, valDate);
      } else {
        throw new OpenGammaRuntimeException("Cannot not handle surfaces with x-axis type " + x.getClass());
      }
      final double forward = forwardCurve.getForward(t);
      final double zerobond = discountCurve.getDiscountFactor(t);
      final Double[] ysAsDoubles = getYs(rawSurface.getYs());
      for (final Double strike : ysAsDoubles) {
        final Double price = rawSurface.getVolatility(x, strike);
        if (price != null) {
          try {
            if (quoteTypeIsCallPutStrike) {
              optionIsCall = strike > callAboveStrike ? true : false;
            }
            final double vol;
            if (isAmerican) {
              vol = americanModel.impliedVolatility(price, spot, strike, -Math.log(zerobond) / t, Math.log(forward / spot) / t, t, optionIsCall);
            } else {
              final double fwdPrice = price / zerobond;
              vol = BlackFormulaRepository.impliedVolatility(fwdPrice, forward, strike, t, optionIsCall);
            }
            tList.add(t);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.option.pricing.analytic.BjerksundStenslandModel

  }

  @Test(enabled = false)
  public void debugTest() {
    System.out.println("BlackScholesMertonPDEPricerTest.debugTest");
    final BjerksundStenslandModel amPricer = new BjerksundStenslandModel();
    final BlackScholesMertonPDEPricer pricer = new BlackScholesMertonPDEPricer(false);
    final double s0 = 10.0;
    final double k = 7.0;
    final double r = 0.2;
    final double b = 0.1;
    final double t = 2.0;
    final double sigma = 0.3;
    final boolean isCall = false;
    final boolean isAmerican = true;

    final double nu = 80;
    final int tSteps = 500;
    final int sSteps = (int) (nu * tSteps);
    // warm-up
    pricer.price(s0, k, r, b, t, sigma, isCall, false, sSteps, tSteps);

    final double df = Math.exp(-r * t);
    final double fwd = s0 * Math.exp(b * t);
    final double bsPrice = df * BlackFormulaRepository.price(fwd, k, t, sigma, isCall);
    final double startTime = System.nanoTime() / 1e6;
    final double pdePrice = pricer.price(s0, k, r, b, t, sigma, isCall, isAmerican, sSteps, tSteps);
    final double endTime = System.nanoTime() / 1e6;
    final double duration = endTime - startTime;


    final double amPrice = amPricer.price(s0, k, r, b, t, sigma, isCall);
    final double relErr = Math.abs(1 - pdePrice / amPrice);
    System.out.println(tSteps + "\t" + sSteps + "\t" + duration + df * fwd + "\t" + amPrice + "\t" + pdePrice + "\t" + relErr);

  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.option.pricing.analytic.BjerksundStenslandModel

      throw new OpenGammaRuntimeException("Unexpected InstrumentDerivative type");
    }
    final double spot = market.getForwardCurve().getSpot();
    final double discountRate = market.getDiscountCurve().getInterestRate(timeToExpiry);
    final double costOfCarry = discountRate - Math.log(market.getForwardCurve().getForward(timeToExpiry) / spot) / timeToExpiry;
    final double impliedVol = (new BjerksundStenslandModel()).impliedVolatility(optionPrice, spot, strike, discountRate, costOfCarry, timeToExpiry, isCall);

    final ValueSpecification resultSpec = new ValueSpecification(getValueRequirementNames()[0], targetSpec, resultProperties);
    return Collections.singleton(new ComputedValue(resultSpec, impliedVol));
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.option.pricing.analytic.BjerksundStenslandModel

          for (int l = 0; l < nVols; ++l) {
            for (int n = 0; n < nTf; ++n) {
              for (int i = 0; i < nDiv; ++i) {
                final OptionFunctionProvider1D function = new AmericanVanillaOptionFunctionProvider(STRIKES[k], time, steps, tfSet[n]);
                final GreekResultCollection resNew = _model.getGreeks(lattice, function, SPOT, VOLS[l], INTERESTS[j], DIVIDENDS[i]);
                final BjerksundStenslandModel bs = new BjerksundStenslandModel();
                final double[] first = bs.getPriceAdjoint(SPOT, STRIKES[k], INTERESTS[j], INTERESTS[j] - DIVIDENDS[i], time, VOLS[l], tfSet[n]);
                final double[] deltaGamma = bs.getPriceDeltaGamma(SPOT, STRIKES[k], INTERESTS[j], INTERESTS[j] - DIVIDENDS[i], time, VOLS[l], tfSet[n]);
                //                System.out.println(SPOT + "\t" + STRIKES[k] + "\t" + INTERESTS[j] + "\t" + DIVIDENDS[i] + "\t" + time + "\t" + VOLS[l] + "\t" + tfSet[n] + "\t" + m);
                assertEquals(resNew.get(Greek.FAIR_PRICE), deltaGamma[0], Math.abs(deltaGamma[0]));
                assertEquals(resNew.get(Greek.DELTA), deltaGamma[1], Math.abs(deltaGamma[1]));
                /*
                 * If the spot is close to the exercise boundary, c_{20} = c_{21} = c_{22} sometimes occurs in some lattice specification leading to vanishing gamma
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.