Package com.opengamma.util.money

Examples of com.opengamma.util.money.CurrencyAmount


  }

  public static CurrencyAmount getNotional(final Security security, final CurrencyPairs currencyPairs, final SecuritySource securitySource) {
    if (security instanceof FinancialSecurity) {
      final FinancialSecurity finSec = (FinancialSecurity) security;
      final CurrencyAmount notional = finSec.accept(new FinancialSecurityVisitorAdapter<CurrencyAmount>() {

        @Override
        public CurrencyAmount visitSwapSecurity(final SwapSecurity security) {
          final SwapLeg payNotional = security.getPayLeg();
          final SwapLeg receiveNotional = security.getReceiveLeg();
          if (payNotional.getNotional() instanceof InterestRateNotional && receiveNotional.getNotional() instanceof InterestRateNotional) {
            final InterestRateNotional pay = (InterestRateNotional) payNotional.getNotional();
            final InterestRateNotional receive = (InterestRateNotional) receiveNotional.getNotional();
            if (Double.compare(pay.getAmount(), receive.getAmount()) == 0) {
              return CurrencyAmount.of(pay.getCurrency(), pay.getAmount());
            }
          }
          throw new OpenGammaRuntimeException("Can only handle interest rate notionals with the same amounts");
        }

        @Override
        public CurrencyAmount visitFXOptionSecurity(final FXOptionSecurity security) {
          final Currency currency1 = security.getPutCurrency();
          final double amount1 = security.getPutAmount();
          final Currency currency2 = security.getCallCurrency();
          final double amount2 = security.getCallAmount();
          final CurrencyPair currencyPair = currencyPairs.getCurrencyPair(currency1, currency2);
          if (currencyPair.getBase().equals(currency1)) {
            return CurrencyAmount.of(currency1, amount1);
          }
          return CurrencyAmount.of(currency2, amount2);
        }

        @Override
        public CurrencyAmount visitFXBarrierOptionSecurity(final FXBarrierOptionSecurity security) {
          final Currency currency1 = security.getPutCurrency();
          final double amount1 = security.getPutAmount();
          final Currency currency2 = security.getCallCurrency();
          final double amount2 = security.getCallAmount();
          final CurrencyPair currencyPair = currencyPairs.getCurrencyPair(currency1, currency2);
          if (currencyPair.getBase().equals(currency1)) {
            return CurrencyAmount.of(currency1, amount1);
          }
          return CurrencyAmount.of(currency2, amount2);
        }

        @Override
        public CurrencyAmount visitNonDeliverableFXOptionSecurity(final NonDeliverableFXOptionSecurity security) {
          final Currency currency = security.getDeliveryCurrency();
          final double amount = security.getCallCurrency().equals(currency) ? security.getCallAmount() : security.getPutAmount();
          return CurrencyAmount.of(currency, amount);
        }

        @Override
        public CurrencyAmount visitFXDigitalOptionSecurity(final FXDigitalOptionSecurity security) {
          final Currency currency1 = security.getPutCurrency();
          final double amount1 = security.getPutAmount();
          final Currency currency2 = security.getCallCurrency();
          final double amount2 = security.getCallAmount();
          final CurrencyPair currencyPair = currencyPairs.getCurrencyPair(currency1, currency2);
          if (currencyPair.getBase().equals(currency1)) {
            return CurrencyAmount.of(currency1, amount1);
          }
          return CurrencyAmount.of(currency2, amount2);
        }

        @Override
        public CurrencyAmount visitNonDeliverableFXDigitalOptionSecurity(final NonDeliverableFXDigitalOptionSecurity security) {
          final Currency currency = security.getPaymentCurrency();
          final double amount = security.getCallCurrency().equals(currency) ? security.getCallAmount() : security.getPutAmount();
          return CurrencyAmount.of(currency, amount);
        }

        @Override
        public CurrencyAmount visitFXForwardSecurity(final FXForwardSecurity security) {
          final Currency currency1 = security.getPayCurrency();
          final double amount1 = security.getPayAmount();
          final Currency currency2 = security.getReceiveCurrency();
          final double amount2 = security.getReceiveAmount();
          final CurrencyPair currencyPair = currencyPairs.getCurrencyPair(currency1, currency2);
          if (currencyPair.getBase().equals(currency1)) {
            return CurrencyAmount.of(currency1, amount1);
          }
          return CurrencyAmount.of(currency2, amount2);
        }

        @Override
        public CurrencyAmount visitStandardVanillaCDSSecurity(final StandardVanillaCDSSecurity security) {
          final InterestRateNotional notional = security.getNotional();
          final int sign = security.isBuy() ? 1 : -1;
          return CurrencyAmount.of(notional.getCurrency(), sign * notional.getAmount());
        }

        @Override
        public CurrencyAmount visitLegacyVanillaCDSSecurity(final LegacyVanillaCDSSecurity security) {
          final InterestRateNotional notional = security.getNotional();
          final int sign = security.isBuy() ? 1 : -1;
          return CurrencyAmount.of(notional.getCurrency(), sign * notional.getAmount());
        }

        @Override
        public CurrencyAmount visitGovernmentBondSecurity(final GovernmentBondSecurity security) {
          final Currency currency = security.getCurrency();
          final double notional = security.getMinimumAmount();
          return CurrencyAmount.of(currency, notional);
        }

        @Override
        public CurrencyAmount visitCorporateBondSecurity(final CorporateBondSecurity security) {
          final Currency currency = security.getCurrency();
          final double notional = security.getMinimumAmount();
          return CurrencyAmount.of(currency, notional);
        }

        @Override
        public CurrencyAmount visitMunicipalBondSecurity(final MunicipalBondSecurity security) {
          final Currency currency = security.getCurrency();
          final double notional = security.getMinimumAmount();
          return CurrencyAmount.of(currency, notional);
        }

        @Override
        public CurrencyAmount visitSwaptionSecurity(final SwaptionSecurity security) {
          final Security underlying = securitySource.getSingle(ExternalIdBundle.of(security.getUnderlyingId()));
          Preconditions.checkState(underlying instanceof SwapSecurity, "Failed to resolve underlying SwapSecurity. DB record potentially corrupted. '%s' returned.", underlying);
          return visitSwapSecurity((SwapSecurity) underlying);
        }

        @Override
        public CurrencyAmount visitEquityIndexOptionSecurity(final EquityIndexOptionSecurity security) {
          final Currency currency = security.getCurrency();
          final double notional = security.getPointValue();
          return CurrencyAmount.of(currency, notional);
        }

        @Override
        public CurrencyAmount visitInterestRateFutureSecurity(final InterestRateFutureSecurity security) {
          final Currency currency = security.getCurrency();
          final double notional = security.getUnitAmount();
          return CurrencyAmount.of(currency, notional);
        }

        @Override
        public CurrencyAmount visitFederalFundsFutureSecurity(final FederalFundsFutureSecurity security) {
          final Currency currency = security.getCurrency();
          final double notional = security.getUnitAmount();
          return CurrencyAmount.of(currency, notional);
        }

        @Override
        public CurrencyAmount visitCreditDefaultSwapIndexSecurity(final CreditDefaultSwapIndexSecurity security) {
          final InterestRateNotional notional = security.getNotional();
          return CurrencyAmount.of(notional.getCurrency(), notional.getAmount());
        }

        @Override
        public CurrencyAmount visitCreditDefaultSwapOptionSecurity(final CreditDefaultSwapOptionSecurity security) {
          final Currency currency = security.getCurrency();
View Full Code Here


  @Test
  public void currencyAmountCanHaveCurrencyOutput() {

    ResultsFormatter formatter = new ResultsFormatter();
    CurrencyAmount value = CurrencyAmount.of(Currency.USD, 123.45);
    Object result = formatter.format(value, null, TypeFormatter.Format.CELL, null);

    assertTrue(result instanceof String);
    assertEquals(result, "USD 123.45");
  }
View Full Code Here

  @Test
  public void currencyAmountCanHaveCurrencySuppressed() {

    ResultsFormatter formatter = new ResultsFormatter(SUPPRESS_CURRENCY);
    CurrencyAmount value = CurrencyAmount.of(Currency.USD, 123.45);
    Object result = formatter.format(value, null, TypeFormatter.Format.CELL, null);

    assertTrue(result instanceof String);
    assertEquals(result, "123.45");
  }
View Full Code Here

  public InterestRateCurveSensitivity forwardModifiedCurveSensitivity(final Swap<CouponFixedAccruedCompounding, CouponONCompounded> fixedCouponSwap, final YieldCurveBundle curves) {
    ArgumentChecker.notNull(fixedCouponSwap, "Swap");
    ArgumentChecker.isTrue(fixedCouponSwap.getFirstLeg().getNumberOfPayments() == 1, "Swap should have one fixed payment");
    ArgumentChecker.isTrue(fixedCouponSwap.getSecondLeg().getNumberOfPayments() == 1, "Swap should have one floating payment");
    CouponFixedAccruedCompounding cpnFixed = fixedCouponSwap.getFirstLeg().getNthPayment(0);
    CurrencyAmount pvLegFloating = METHOD_COUPON_ON_CMP.presentValue(fixedCouponSwap.getSecondLeg().getNthPayment(0), curves);
    double dfPay = curves.getCurve(cpnFixed.getFundingCurveName()).getDiscountFactor(cpnFixed.getPaymentTime());
    //    double rate = -pvLegFloating.getAmount() / (dfPay * cpnFixed.getNotional()) - 1.0d;
    // Backward sweep
    double rateBar = 1.0;
    double pvFloatingBar = -1.0d / (dfPay * cpnFixed.getNotional()) * rateBar;
    double dfBar = pvLegFloating.getAmount() / (dfPay * dfPay * cpnFixed.getNotional()) * rateBar;
    final double dfDr = -cpnFixed.getPaymentTime() * dfPay;
    final List<DoublesPair> list = new ArrayList<>();
    list.add(new DoublesPair(cpnFixed.getPaymentTime(), dfDr * dfBar));
    final Map<String, List<DoublesPair>> dfMap = new HashMap<>();
    dfMap.put(cpnFixed.getFundingCurveName(), list);
View Full Code Here

    final SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationEngine calibrationEngine = new SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationEngine(objective, nbStrikes);
    final SwaptionPhysicalFixedIbor[] swaptionCalibration = METHOD_BASKET.calibrationBasketFixedLegPeriod(swaption, _strikeMoneyness);
    calibrationEngine.addInstrument(swaptionCalibration, METHOD_SWAPTION_SABR);
    calibrationEngine.calibrate(curves);
    final LiborMarketModelDisplacedDiffusionDataBundle lmmBundle = new LiborMarketModelDisplacedDiffusionDataBundle(lmmParameters, curves);
    final CurrencyAmount pv = METHOD_SWAPTION_LMM.presentValue(swaption, lmmBundle);
    return pv;
  }
View Full Code Here

    calibrationEngine.calibrate(curves);
    final LiborMarketModelDisplacedDiffusionDataBundle lmmBundle = new LiborMarketModelDisplacedDiffusionDataBundle(lmmParameters, curves);

    // 1. PV

    final CurrencyAmount pv = METHOD_SWAPTION_LMM.presentValue(swaption, lmmBundle);

    final int nbCalibrations = swaptionCalibration.length;
    final int nbPeriods = nbCalibrations / nbStrikes;
    final int nbFact = lmmParameters.getNbFactor();
    final List<Integer> instrumentIndex = calibrationEngine.getInstrumentIndex();
View Full Code Here

  @Test
  /**
   * Tests the present value against explicit computation.
   */
  public void presentValue() {
    final CurrencyAmount pvTransactionComputed = METHOD_TRANSACTION.presentValue(BILL_TRA, CURVE_BUNDLE);
    CurrencyAmount pvSecurity = METHOD_SECURITY.presentValue(BILL_TRA.getBillPurchased(), CURVE_BUNDLE);
    pvSecurity = pvSecurity.multipliedBy(QUANTITY);
    final double pvSettle = BILL_TRA_DEFINITION.getSettlementAmount() * CURVE_BUNDLE.getCurve(NAME_CURVES[0]).getDiscountFactor(BILL_TRA.getBillPurchased().getSettlementTime());
    assertEquals("Bill Security: discounting method - present value", pvSecurity.plus(pvSettle).getAmount(), pvTransactionComputed.getAmount(), TOLERANCE_PV);
  }
View Full Code Here

  @Test
  /**
   * Tests the present value: Method vs Calculator
   */
  public void presentValueMethodVsCalculator() {
    final CurrencyAmount pvMethod = METHOD_TRANSACTION.presentValue(BILL_TRA, CURVE_BUNDLE);
    final double pvCalculator = BILL_TRA.accept(PVC, CURVE_BUNDLE);
    assertEquals("Bill Security: discounting method - present value", pvMethod.getAmount(), pvCalculator, TOLERANCE_PV);
  }
View Full Code Here

   */
  public void parSpread() {
    final double spread = METHOD_TRANSACTION.parSpread(BILL_TRA, CURVE_BUNDLE);
    final BillTransactionDefinition bill0Definition = BillTransactionDefinition.fromYield(BILL_SEC_DEFINITION, QUANTITY, SETTLE_DATE, YIELD + spread, CALENDAR);
    final BillTransaction bill0 = bill0Definition.toDerivative(REFERENCE_DATE, NAME_CURVES);
    final CurrencyAmount pv0 = METHOD_TRANSACTION.presentValue(bill0, CURVE_BUNDLE);
    assertEquals("Bill Security: discounting method - par spread", 0, pv0.getAmount(), TOLERANCE_PV);
  }
View Full Code Here

   * @return The present value.
   */
  public CurrencyAmount presentValuePositiveNotional(final AnnuityCouponFixed annuity, final MulticurveProviderInterface multicurves) {
    ArgumentChecker.notNull(annuity, "Annuity");
    ArgumentChecker.notNull(multicurves, "Multi-curves provider");
    CurrencyAmount pv = CurrencyAmount.of(annuity.getCurrency(), 0);
    for (final CouponFixed cpn : annuity.getPayments()) {
      pv = pv.plus(METHOD_CPN_FIXED.presentValuePositiveNotional(cpn, multicurves));
    }
    return 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.