Package com.opengamma.util.money

Examples of com.opengamma.util.money.CurrencyAmount


    // Calibration
    calibrationEngine.calibrate(curves);
    final HullWhiteOneFactorPiecewiseConstantDataBundle hwBundle = new HullWhiteOneFactorPiecewiseConstantDataBundle(hwParameters, curves);
    // Pricing
    final HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), DEFAULT_NB_PATH);
    final CurrencyAmount pvMC = methodMC.presentValue(swaption, swaption.getCurrency(), swaption.getUnderlyingSwap().getFirstLeg().getDiscountCurve(), hwBundle);
    return pvMC.getAmount();
  }
View Full Code Here


  /**
   * Performance for a high number of paths.
   */
  public void performance() {
    long startTime, endTime;
    final CurrencyAmount pvExplicit = METHOD_HW.presentValue(CAP_LONG, BUNDLE_HW);
    HullWhiteMonteCarloMethod methodMC;
    final int nbPath = 1000000;
    methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), nbPath);
    final int nbTest = 10;
    final double[] pv = new double[nbTest];
    final double[] pvDiff = new double[nbTest];
    startTime = System.currentTimeMillis();
    for (int looptest = 0; looptest < nbTest; looptest++) {
      pv[looptest] = methodMC.presentValue(CAP_LONG, CUR, CURVES_NAME[0], BUNDLE_HW).getAmount();
      pvDiff[looptest] = pv[looptest] - pvExplicit.getAmount();
    }
    endTime = System.currentTimeMillis();
    System.out.println(nbTest + " pv cap/floor Hull-White MC method (" + nbPath + " paths): " + (endTime - startTime) + " ms");
    // Performance note: price: 12-Jun-12: On Mac Pro 3.2 GHz Quad-Core Intel Xeon: 2400 ms for 10 cap with 1,000,000 paths.
  }
View Full Code Here

    // Calibration
    calibrationEngine.calibrate(curves);
    final HullWhiteOneFactorPiecewiseConstantDataBundle hwBundle = new HullWhiteOneFactorPiecewiseConstantDataBundle(hwParameters, curves);
    // Pricing
    final HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), DEFAULT_NB_PATH);
    final CurrencyAmount pvMC = methodMC.presentValue(annuity, annuity.getCurrency(), annuity.getDiscountCurve(), hwBundle);
    return pvMC.getAmount();
  }
View Full Code Here

      final FudgeMsg perDateMessage = (FudgeMsg) pairsField.get(i).getValue();
      final List<FudgeField> caMessage = perDateMessage.getAllByName(CA_FIELD);
      final List<FudgeField> resetIndexMessage = perDateMessage.getAllByName(RESET_INDEX_FIELD);
      final List<Pair<CurrencyAmount, String>> list = Lists.newArrayListWithCapacity(caMessage.size());
      for (int j = 0; j < caMessage.size(); j++) {
        final CurrencyAmount ca = deserializer.fieldValueToObject(CurrencyAmount.class, caMessage.get(j));
        final String resetIndex = (String) deserializer.fieldValueToObject(String.class, resetIndexMessage.get(j));
        list.add(Pair.of(ca, resetIndex));
      }
      values.put(date, list);
    }
View Full Code Here

  private static final double TOLERANCE_PV = 1.0E-2;
  private static final double TOLERANCE_RATE = 1.0E-8;

  @Test
  public void presentValue() {
    final CurrencyAmount pvComputed = METHOD_CPN_IBOR_SPREAD.presentValue(CPN_IBOR_SPREAD, CURVES);
    final double forward = (CURVES.getCurve(CURVE_NAMES[1]).getDiscountFactor(CPN_IBOR_SPREAD.getFixingPeriodStartTime())
        / CURVES.getCurve(CURVE_NAMES[1]).getDiscountFactor(CPN_IBOR_SPREAD.getFixingPeriodEndTime()) - 1.0)
        / CPN_IBOR_SPREAD.getFixingAccrualFactor();
    final double pv = NOTIONAL * CPN_IBOR_SPREAD.getPaymentYearFraction() * (forward + SPREAD) * CURVES.getCurve(CURVE_NAMES[0]).getDiscountFactor(CPN_IBOR_SPREAD.getPaymentTime());
    final CurrencyAmount pvExpected = CurrencyAmount.of(EURIBOR3M.getCurrency(), pv);
    assertEquals("CouponIborSpreadDiscountingMethod: present value", pvExpected.getAmount(), pvComputed.getAmount(), TOLERANCE_PV);
    final CurrencyAmount pvIbor = METHOD_CPN_IBOR.presentValue(CPN_IBOR, CURVES);
    final CurrencyAmount pvFixed = METHOD_FIXED.presentValue(CPN_FIXED, CURVES);
    assertEquals("CouponIborSpreadDiscountingMethod: present value", pvIbor.plus(pvFixed).getAmount(), pvComputed.getAmount(), TOLERANCE_PV);
  }
View Full Code Here

    assertEquals("CouponIborSpreadDiscountingMethod: present value", pvIbor.plus(pvFixed).getAmount(), pvComputed.getAmount(), TOLERANCE_PV);
  }

  @Test
  public void presentValueNoSpreadPositivNotional() {
    final CurrencyAmount pvComputed = METHOD_CPN_IBOR_SPREAD.presentValueNoSpreadPositiveNotional(CPN_IBOR_SPREAD, CURVES);
    final double forward = (CURVES.getCurve(CURVE_NAMES[1]).getDiscountFactor(CPN_IBOR_SPREAD.getFixingPeriodStartTime())
        / CURVES.getCurve(CURVE_NAMES[1]).getDiscountFactor(CPN_IBOR_SPREAD.getFixingPeriodEndTime()) - 1.0)
        / CPN_IBOR_SPREAD.getFixingAccrualFactor();
    final double pv = -NOTIONAL * CPN_IBOR_SPREAD.getPaymentYearFraction() * forward * CURVES.getCurve(CURVE_NAMES[0]).getDiscountFactor(CPN_IBOR_SPREAD.getPaymentTime());
    final CurrencyAmount pvExpected = CurrencyAmount.of(EURIBOR3M.getCurrency(), pv);
    assertEquals("CouponIborSpreadDiscountingMethod: present value", pvExpected.getAmount(), pvComputed.getAmount(), TOLERANCE_PV);
  }
View Full Code Here

    final double forward = spot * dfForeign / dfDomestic;
    final double volatility = black.getVolatility(optionForex.getCurrency1(), optionForex.getCurrency2(), optionForex.getTimeToExpiry());
    final BlackFunctionData dataBlack = new BlackFunctionData(forward, dfDomestic, volatility);
    final Function1D<BlackFunctionData, Double> func = BLACK_FUNCTION.getPriceFunction(optionForex);
    final double price = func.evaluate(dataBlack) * Math.abs(optionForex.getUnderlyingForex().getPaymentCurrency1().getAmount()) * (optionForex.isLong() ? 1.0 : -1.0);
    final CurrencyAmount priceCurrency = CurrencyAmount.of(optionForex.getUnderlyingForex().getCurrency2(), price);
    return MultipleCurrencyAmount.of(priceCurrency);
  }
View Full Code Here

  @Test(enabled = true)
  /**
   * Tests the present value of the Hull-White Monte-Carlo calibrated to SABR swaption.
   */
  public void presentValueSABRHullWhiteMonteCarlo() {
    final CurrencyAmount pvSABR = METHOD.presentValue(SWAPTION_LONG_PAYER, SABR_BUNDLE);
    final PresentValueSABRHullWhiteMonteCarloCalculator pvcSABRHWMC = PresentValueSABRHullWhiteMonteCarloCalculator.getInstance();
    final double pvMC = SWAPTION_LONG_PAYER.accept(pvcSABRHWMC, SABR_BUNDLE);
    assertEquals("Swaption Physical SABR: Present value using Hull-White by Monte Carlo", pvSABR.getAmount(), pvMC, 2.5E+4);
  }
View Full Code Here

    final ForexDefinition forexUnderlyingDefinition = new ForexDefinition(EUR, USD, payDate, notional, strike);
    final ForexOptionVanillaDefinition forexOptionDefinition = new ForexOptionVanillaDefinition(forexUnderlyingDefinition, expDate, isCall, isLong);
    final ForexOptionVanilla forexOption = forexOptionDefinition.toDerivative(REFERENCE_DATE);
    final double gammaRelative = METHOD_OPTION.gammaRelative(forexOption, SMILE_MULTICURVES, true);
    final double gammaExpected = gammaRelative * notional;
    final CurrencyAmount gammaComputed = METHOD_OPTION.gamma(forexOption, SMILE_MULTICURVES, true);
    assertEquals("Forex: relative gamma", 1.0, gammaExpected / gammaComputed.getAmount(), TOLERANCE_PV);
  }
View Full Code Here

    final ForexDefinition forexUnderlyingDefinition = new ForexDefinition(USD, EUR, payDate, notional, 1.0 / strike);
    final ForexOptionVanillaDefinition forexOptionDefinition = new ForexOptionVanillaDefinition(forexUnderlyingDefinition, expDate, isCall, isLong);
    final ForexOptionVanilla forexOption = forexOptionDefinition.toDerivative(REFERENCE_DATE);
    final double gammaRelative = METHOD_OPTION.gammaRelative(forexOption, SMILE_MULTICURVES, false);
    final double gammaExpected = gammaRelative * notional;
    final CurrencyAmount gammaComputed = METHOD_OPTION.gamma(forexOption, SMILE_MULTICURVES, false);
    assertEquals("Forex: relative gamma", 1.0, gammaExpected / gammaComputed.getAmount(), TOLERANCE_PV);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.util.money.CurrencyAmount

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.