Package com.opengamma.analytics.financial.instrument.swap

Examples of com.opengamma.analytics.financial.instrument.swap.SwapDefinition


      assertEquals("Sensitivity to forward curve: Node " + i, resFwd[i], pair.getSecond(), deltaTolerance);
    }
    // 2. Funding curve sensitivity
    final String[] bumpedCurvesFundingName = {bumpedCurveName, FORWARD_CURVE_NAME};
    final SwaptionCashFixedIbor swaptionBumpedFunding = swaptionDefinitionLongPayerHighStrike.toDerivative(REFERENCE_DATE, bumpedCurvesFundingName);
    final SwapDefinition underlyingSwap = swaptionDefinitionLongPayerHighStrike.getUnderlyingSwap();
    AnnuityDefinition<? extends PaymentDefinition> floatLeg;
    if (underlyingSwap.getFirstLeg() instanceof AnnuityCouponFixedDefinition) {
      floatLeg = underlyingSwap.getSecondLeg();
    } else {
      floatLeg = underlyingSwap.getFirstLeg();
    }
    final int nbPayDate = floatLeg.getPayments().length;
    final YieldAndDiscountCurve curveFunding = curves.getCurve(FUNDING_CURVE_NAME);
    final double[] yieldsFunding = new double[nbPayDate + 2];
    final double[] nodeTimesFunding = new double[nbPayDate + 2];
View Full Code Here


    final CurveBuildingBlockBundle blocks7 = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(indexEur).getSecond();
    blocks7.addAll(CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(1).getSecond());
    final double spreadJPYEUR = 0.0010; // 10bps
    final GeneratorAttributeFX attr6Mx5Y = new GeneratorAttributeFX(Period.ofMonths(6), Period.ofYears(5), FX_MATRIX); //TODO Check dates swap
    final double notional = 100000;
    final SwapDefinition swapDefinition = JPYLIBOR3MEURIBOR3M.generateInstrument(NOW, spreadJPYEUR, notional, attr6Mx5Y);
    final InstrumentDerivative swap = swapDefinition.toDerivative(NOW);
    final ParameterSensitivityParameterCalculator<MulticurveProviderInterface> PSC = new ParameterSensitivityParameterCalculator<>(PVCSDC);
    final MarketQuoteSensitivityBlockCalculator<MulticurveProviderInterface> MQSC = new MarketQuoteSensitivityBlockCalculator<>(PSC);
    @SuppressWarnings("unused")
    final MultipleCurrencyParameterSensitivity mqs = MQSC.fromInstrument(swap, multicurves7, blocks7);
    //    int t = 0;
View Full Code Here

      assertEquals("Node " + i, res, pair.getSecond(), deltaTolerance);
    }
    // 2. Funding curve sensitivity
    final String[] bumpedCurvesFundingName = {bumpedCurveName, FORWARD_CURVE_NAME};
    final SwaptionPhysicalFixedIbor swaptionBumpedFunding = SWAPTION_DEFINITION_LONG_PAYER.toDerivative(REFERENCE_DATE, bumpedCurvesFundingName);
    final SwapDefinition underlyingSwap = SWAPTION_DEFINITION_LONG_PAYER.getUnderlyingSwap();
    AnnuityDefinition<? extends PaymentDefinition> floatLeg;
    if (underlyingSwap.getFirstLeg() instanceof AnnuityCouponFixedDefinition) {
      floatLeg = underlyingSwap.getSecondLeg();
    } else {
      floatLeg = underlyingSwap.getFirstLeg();
    }
    final int nbPayDate = floatLeg.getPayments().length;
    final YieldAndDiscountCurve curveFunding = curves.getCurve(FUNDING_CURVE_NAME);
    final double[] yieldsFunding = new double[nbPayDate + 1];
    final double[] nodeTimesFunding = new double[nbPayDate + 1];
View Full Code Here

      assertEquals("Node " + i, res, pair.getSecond(), deltaTolerance);
    }
    // 2. Funding curve sensitivity
    final String[] bumpedCurvesFundingName = {bumpedCurveName, FORWARD_CURVE_NAME };
    final SwaptionCashFixedIbor swaptionBumpedFunding = SWAPTION_DEFINITION_LONG_PAYER.toDerivative(REFERENCE_DATE, bumpedCurvesFundingName);
    final SwapDefinition underlyingSwap = SWAPTION_DEFINITION_LONG_PAYER.getUnderlyingSwap();
    AnnuityDefinition<? extends PaymentDefinition> floatLeg;
    if (underlyingSwap.getFirstLeg() instanceof AnnuityCouponFixedDefinition) {
      floatLeg = underlyingSwap.getSecondLeg();
    } else {
      floatLeg = underlyingSwap.getFirstLeg();
    }
    final int nbPayDate = floatLeg.getPayments().length;
    final YieldAndDiscountCurve curveFunding = curves.getCurve(FUNDING_CURVE_NAME);
    final double[] yieldsFunding = new double[nbPayDate + 2];
    final double[] nodeTimesFunding = new double[nbPayDate + 2];
View Full Code Here

  public InstrumentDefinition<?> visitSwaptionSecurity(final SwaptionSecurity swaptionSecurity) {
    ArgumentChecker.notNull(swaptionSecurity, "swaption security");
    final ExternalId underlyingIdentifier = swaptionSecurity.getUnderlyingId();
    final ZonedDateTime expiry = swaptionSecurity.getExpiry().getExpiry();
    final InstrumentDefinition<?> underlyingSwap = ((SwapSecurity) _securitySource.getSingle(ExternalIdBundle.of(underlyingIdentifier))).accept(_swapConverter);
    final SwapDefinition swapDefinition = (SwapDefinition) underlyingSwap;
    final boolean isCashSettled = swaptionSecurity.isCashSettled();
    final boolean isLong = swaptionSecurity.isLong();
    if (swaptionSecurity.getCurrency().equals(Currency.BRL)) {
      if (!(swapDefinition instanceof SwapFixedCompoundedONCompoundedDefinition)) {
        throw new OpenGammaRuntimeException("Underlying BRL swap must be fixed compounded / overnight compounded");
View Full Code Here

      default:
        final ZonedDateTime effectiveDate = security.getEffectiveDate();
        final ZonedDateTime maturityDate = security.getMaturityDate();
        final AnnuityDefinition<? extends PaymentDefinition> payLeg = security.getPayLeg().accept(getSwapLegConverter(effectiveDate, maturityDate, true));
        final AnnuityDefinition<? extends PaymentDefinition> receiveLeg = security.getReceiveLeg().accept(getSwapLegConverter(effectiveDate, maturityDate, false));
        return new SwapDefinition(payLeg, receiveLeg);
    }
  }
View Full Code Here

  public static GeneratorInstrument<GeneratorAttributeIR> getSwapGenerator(final SwaptionSecurity security, final InstrumentDefinition<?> swaption, final SecuritySource securitySource) {
    ArgumentChecker.notNull(security, "security");
    ArgumentChecker.notNull(swaption, "swaption");
    ArgumentChecker.notNull(securitySource, "security source");
    SwapDefinition swap;
    if (swaption instanceof SwaptionPhysicalFixedIborDefinition) {
      swap = ((SwaptionPhysicalFixedIborDefinition) swaption).getUnderlyingSwap();
    } else if (swaption instanceof SwaptionCashFixedIborDefinition) {
      swap = ((SwaptionCashFixedIborDefinition) swaption).getUnderlyingSwap();
    } else if (swaption instanceof SwaptionPhysicalFixedCompoundedONCompoundedDefinition) {
      swap = ((SwaptionPhysicalFixedCompoundedONCompoundedDefinition) swaption).getUnderlyingSwap();
    } else if (swaption instanceof SwaptionCashFixedCompoundedONCompoundingDefinition) {
      swap = ((SwaptionCashFixedCompoundedONCompoundingDefinition) swaption).getUnderlyingSwap();
    } else {
      throw new OpenGammaRuntimeException("Can only handle cash- and physically-settled ibor swaptions");
    }
    final SwapSecurity underlyingSecurity = (SwapSecurity) securitySource.getSingle(ExternalIdBundle.of(security.getUnderlyingId()));
    FixedInterestRateLeg fixedLeg;
    FloatingInterestRateLeg floatLeg;
    if (underlyingSecurity.getPayLeg() instanceof FixedInterestRateLeg) {
      fixedLeg = (FixedInterestRateLeg) underlyingSecurity.getPayLeg();
      floatLeg = (FloatingInterestRateLeg) underlyingSecurity.getReceiveLeg();
    } else {
      fixedLeg = (FixedInterestRateLeg) underlyingSecurity.getReceiveLeg();
      floatLeg = (FloatingInterestRateLeg) underlyingSecurity.getPayLeg();
    }
    switch (floatLeg.getFloatingRateType()) {
      case IBOR: {
        AnnuityCouponIborDefinition iborLeg;
        if (swap.getFirstLeg() instanceof AnnuityCouponIborDefinition) {
          iborLeg = (AnnuityCouponIborDefinition) swap.getFirstLeg();
        } else if (swap.getSecondLeg() instanceof AnnuityCouponIborDefinition) {
          iborLeg = (AnnuityCouponIborDefinition) swap.getSecondLeg();
        } else {
          throw new OpenGammaRuntimeException("Could not find ibor leg for " + underlyingSecurity);
        }
        final IborIndex iborIndex = iborLeg.getIborIndex();
        final Calendar calendar = iborLeg.getIborCalendar();
        final DayCount fixedLegDayCount = fixedLeg.getDayCount();
        final Frequency frequency = fixedLeg.getFrequency();
        final Period fixedLegPeriod;
        if (frequency instanceof PeriodFrequency) {
          fixedLegPeriod = ((PeriodFrequency) frequency).getPeriod();
        } else if (frequency instanceof SimpleFrequency) {
          fixedLegPeriod = ((SimpleFrequency) frequency).toPeriodFrequency().getPeriod();
        } else {
          throw new OpenGammaRuntimeException("Can only handle PeriodFrequency or SimpleFrequency");
        }
        return new GeneratorSwapFixedIbor("Swap Generator", fixedLegPeriod, fixedLegDayCount, iborIndex, calendar);
      }
      case OIS: {
        IndexON onIndex;
        Calendar calendar;
        if (swap.getFirstLeg() instanceof AnnuityCouponONDefinition) {
          final AnnuityCouponONDefinition annuityCouponONDefinition = (AnnuityCouponONDefinition) swap.getFirstLeg();
          onIndex = annuityCouponONDefinition.getOvernightIndex();
          calendar = annuityCouponONDefinition.getCalendar();
        } else if (swap.getSecondLeg() instanceof AnnuityCouponONDefinition) {
          final AnnuityCouponONDefinition annuityCouponONDefinition = (AnnuityCouponONDefinition) swap.getSecondLeg();
          onIndex = annuityCouponONDefinition.getOvernightIndex();
          calendar = annuityCouponONDefinition.getCalendar();
        } else if (swap.getFirstLeg().getNthPayment(0) instanceof CouponONCompoundedDefinition) {
          final CouponONCompoundedDefinition couponONDefinition = (CouponONCompoundedDefinition) swap.getFirstLeg().getNthPayment(0);
          onIndex = couponONDefinition.getIndex();
          calendar = couponONDefinition.getCalendar();
        } else if (swap.getSecondLeg().getNthPayment(0) instanceof CouponONCompoundedDefinition) {
          final CouponONCompoundedDefinition couponONDefinition = (CouponONCompoundedDefinition) swap.getSecondLeg().getNthPayment(0);
          onIndex = couponONDefinition.getIndex();
          calendar = couponONDefinition.getCalendar();
        } else {
          throw new OpenGammaRuntimeException("Could not find overnight leg for " + underlyingSecurity);
        }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.instrument.swap.SwapDefinition

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.