Examples of SwapFixedLegConvention


Examples of com.opengamma.financial.convention.SwapFixedLegConvention

      final Currency currency = Currency.of(message.getString(CURRENCY_FIELD));
      final ExternalId regionCalendar = deserializer.fieldValueToObject(ExternalId.class, message.getByName(REGION_FIELD));
      final StubType stubType = StubType.valueOf(message.getString(STUB_TYPE_FIELD));
      final boolean exchangeNotional = message.getBoolean(EXCHANGE_NOTIONAL_FIELD);
      final int paymentLag = message.getInt(PAYMENT_LAG_FIELD);
      final SwapFixedLegConvention convention = new SwapFixedLegConvention(name, externalIdBundle, paymentTenor, dayCount, businessDayConvention, currency,
          regionCalendar, settlementDays, isEOM, stubType, exchangeNotional, paymentLag);
      final FudgeField uniqueIdMsg = message.getByName(UNIQUE_ID_FIELD);
      if (uniqueIdMsg != null) {
        convention.setUniqueId(deserializer.fieldValueToObject(UniqueId.class, uniqueIdMsg));
      }
      return convention;
    }
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

  public InstrumentDefinition<?> visitZeroCouponInflationNode(final ZeroCouponInflationNode inflationNode) {
    final Double rate = _marketData.getDataPoint(_dataId);
    if (rate == null) {
      throw new OpenGammaRuntimeException("Could not get market data for " + _dataId);
    }
    final SwapFixedLegConvention fixedLegConvention = _conventionSource.getConvention(SwapFixedLegConvention.class, inflationNode.getFixedLegConvention());
    if (fixedLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + inflationNode.getFixedLegConvention() + " was null");
    }
    final InflationLegConvention inflationLegConvention = _conventionSource.getConvention(InflationLegConvention.class, inflationNode.getInflationLegConvention());
    if (inflationLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + inflationNode.getInflationLegConvention() + " was null");
    }
    final PriceIndexConvention priceIndexConvention = _conventionSource.getConvention(PriceIndexConvention.class, inflationLegConvention.getPriceIndexConvention());
    if (priceIndexConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + inflationLegConvention.getPriceIndexConvention() + " was null");
    }
    final int settlementDays = fixedLegConvention.getSettlementDays();
    final Period tenor = inflationNode.getTenor().getPeriod();
    final double notional = 1;
    //TODO business day convention and currency are in both conventions - should we enforce that they're the same or use
    // different ones for each leg?
    final BusinessDayConvention businessDayConvention = fixedLegConvention.getBusinessDayConvention();
    final boolean endOfMonth = fixedLegConvention.isIsEOM();
    final Currency currency = priceIndexConvention.getCurrency();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, priceIndexConvention.getRegion());
    final ZoneId zone = _valuationTime.getZone(); //TODO time zone set to midnight UTC
    final ZonedDateTime settlementDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar).toLocalDate().atStartOfDay(zone);
    final ZonedDateTime paymentDate = ScheduleCalculator.getAdjustedDate(settlementDate, tenor, businessDayConvention, calendar, endOfMonth).toLocalDate().atStartOfDay(zone);
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

      throw new OpenGammaRuntimeException("Convention with id " + underlyingSwapConvention.getPayLegConvention() + " was null");
    }
    if (!(payLegConvention instanceof SwapFixedLegConvention)) {
      throw new OpenGammaRuntimeException("Convention of pay leg was not Fixed Leg for " + underlyingSwapConvention);
    }
    final SwapFixedLegConvention fixedLegConvention = (SwapFixedLegConvention) payLegConvention;
    if (!(receiveLegConvention instanceof VanillaIborLegConvention)) {
      throw new OpenGammaRuntimeException("Convention of pay leg was not Ibor Leg for " + underlyingSwapConvention);
    }
    final VanillaIborLegConvention iborLegConvention = (VanillaIborLegConvention) receiveLegConvention;
    final String expiryCalculatorName = futureConvention.getExpiryConvention().getValue();
    final ZonedDateTime startDate = _valuationTime.plus(swapFuture.getStartTenor().getPeriod());
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, futureConvention.getExchangeCalendar());
    final ExchangeTradedInstrumentExpiryCalculator expiryCalculator = ExchangeTradedInstrumentExpiryCalculatorFactory.getCalculator(expiryCalculatorName);
    final LocalTime time = startDate.toLocalTime();
    final ZoneId timeZone = startDate.getZone();
    final double notional = 1.0;
    final int spotLagSwap = fixedLegConvention.getSettlementDays();
    final ZonedDateTime lastTradeDate = ZonedDateTime.of(expiryCalculator.getExpiryDate(swapFuture.getFutureNumber(), startDate.toLocalDate(), calendar), time, timeZone);
    final ZonedDateTime deliveryDate = ScheduleCalculator.getAdjustedDate(lastTradeDate, spotLagSwap, calendar);
    final Convention underlyingConvention = _conventionSource.getConvention(iborLegConvention.getIborIndexConvention());
    if (!(underlyingConvention instanceof IborIndexConvention)) {
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + iborLegConvention.getIborIndexConvention());
      }
      throw new OpenGammaRuntimeException("Convention of the underlying was not an ibor index convention; have " + underlyingConvention.getClass());
    }
    final IborIndexConvention indexConvention = (IborIndexConvention) underlyingConvention;
    final Currency currency = indexConvention.getCurrency();
    final DayCount dayCount = indexConvention.getDayCount();
    final BusinessDayConvention businessDayConvention = indexConvention.getBusinessDayConvention();
    final boolean eom = indexConvention.isIsEOM();
    final Period indexTenor = iborLegConvention.getResetTenor().getPeriod();
    final int spotLagIndex = indexConvention.getSettlementDays();
    final IborIndex iborIndex = new IborIndex(currency, indexTenor, spotLagIndex, dayCount, businessDayConvention, eom, indexConvention.getName());
    final GeneratorSwapFixedIbor generator = new GeneratorSwapFixedIbor("", fixedLegConvention.getPaymentTenor().getPeriod(), fixedLegConvention.getDayCount(), iborIndex, calendar);
    final SwapFixedIborDefinition underlying = SwapFixedIborDefinition.from(deliveryDate, maturityTenor.getPeriod(), generator, notional, 0.0, false); //FIXME: rate of underlying?
    final SwapFuturesPriceDeliverableSecurityDefinition securityDefinition = new SwapFuturesPriceDeliverableSecurityDefinition(lastTradeDate, underlying, notional);
    return new SwapFuturesPriceDeliverableTransactionDefinition(securityDefinition, _valuationTime, price, 1);
  }
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

        final ExternalId regionId = swapLeg.getRegionId();
        final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
        final InterestRateNotional interestRateNotional = (InterestRateNotional) swapLeg.getNotional();
        final Currency currency = interestRateNotional.getCurrency();
        final String fixedLegConventionName = getConventionName(currency, IRS_FIXED_LEG);
        final SwapFixedLegConvention fixedLegConvention = _conventionSource.getConvention(SwapFixedLegConvention.class, ExternalId.of(SCHEME_NAME, fixedLegConventionName));
        if (fixedLegConvention == null) {
          throw new OpenGammaRuntimeException("Could not get fixed leg convention with the identifier " + ExternalId.of(SCHEME_NAME, fixedLegConventionName));
        }
        final Frequency freqFixed = swapLeg.getFrequency();
        final Period tenorFixed = getTenor(freqFixed);
        final double notional = interestRateNotional.getAmount();
        final DayCount dayCount = fixedLegConvention.getDayCount();
        final boolean isEOM = fixedLegConvention.isIsEOM();
        final double rate = swapLeg.getRate();
        final BusinessDayConvention businessDayConvention = fixedLegConvention.getBusinessDayConvention();
        return AnnuityCouponFixedDefinition.from(currency, effectiveDate, maturityDate, tenorFixed, calendar, dayCount,
            businessDayConvention, isEOM, notional, rate, isPayer);
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitFloatingInterestRateLeg(final FloatingInterestRateLeg swapLeg) {
        final InterestRateNotional interestRateNotional = (InterestRateNotional) swapLeg.getNotional();
        final Currency currency = interestRateNotional.getCurrency();
        final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, swapLeg.getRegionId());
        switch (swapLeg.getFloatingRateType()) {
          case IBOR:
            return getIborAnnuity(swapLeg, interestRateNotional, currency, calendar);
          case OIS:
            return getOISAnnuity(swapLeg, interestRateNotional, currency);
          case CMS:
            return getCMSAnnuity(swapLeg, interestRateNotional, currency, calendar);
          case OVERNIGHT_ARITHMETIC_AVERAGE:
            return getOvernightAAverageAnnuity(swapLeg, interestRateNotional, currency);
          default:
            throw new OpenGammaRuntimeException("Cannot handle floating type " + swapLeg.getFloatingRateType());
        }
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitFloatingSpreadIRLeg(final FloatingSpreadIRLeg swapLeg) {
        final InterestRateNotional interestRateNotional = (InterestRateNotional) swapLeg.getNotional();
        final Currency currency = interestRateNotional.getCurrency();
        final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, swapLeg.getRegionId());
        switch (swapLeg.getFloatingRateType()) {
          case IBOR:
            return getIborAnnuity(swapLeg, interestRateNotional, currency, calendar);
          case OIS:
            return getOISAnnuity(swapLeg, interestRateNotional, currency);
          case CMS:
            return getCMSAnnuity(swapLeg, interestRateNotional, currency, calendar);
          case OVERNIGHT_ARITHMETIC_AVERAGE:
            return getOvernightAAverageAnnuity(swapLeg, interestRateNotional, currency);
          default:
            throw new OpenGammaRuntimeException("Cannot handle floating type " + swapLeg.getFloatingRateType());
        }
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitFloatingGearingIRLeg(final FloatingGearingIRLeg swapLeg) {
        throw new OpenGammaRuntimeException("Cannot handle " + swapLeg.getClass());
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitFixedVarianceSwapLeg(final FixedVarianceSwapLeg swapLeg) {
        throw new OpenGammaRuntimeException("Cannot handle " + swapLeg.getClass());
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitFloatingVarianceSwapLeg(final FloatingVarianceSwapLeg swapLeg) {
        throw new OpenGammaRuntimeException("Cannot handle " + swapLeg.getClass());
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitFixedInflationSwapLeg(final FixedInflationSwapLeg swapLeg) {
        throw new OpenGammaRuntimeException("Cannot handle " + swapLeg.getClass());
      }

      @Override
      public final AnnuityDefinition<? extends PaymentDefinition> visitInflationIndexSwapLeg(final InflationIndexSwapLeg swapLeg) {
        throw new OpenGammaRuntimeException("Cannot handle " + swapLeg.getClass());
      }

      private AnnuityDefinition<? extends PaymentDefinition> getIborAnnuity(final FloatingInterestRateLeg swapLeg, final InterestRateNotional interestRateNotional,
          final Currency currency, final Calendar calendar) {
        final String tenorString = getTenorString(swapLeg.getFrequency());
        final String iborLegConventionName = getConventionName(currency, tenorString, IRS_IBOR_LEG);
        final VanillaIborLegConvention iborLegConvention = _conventionSource.getConvention(VanillaIborLegConvention.class, ExternalId.of(SCHEME_NAME, iborLegConventionName));
        if (iborLegConvention == null) {
          throw new OpenGammaRuntimeException("Could not get Ibor leg convention with the identifier " + ExternalId.of(SCHEME_NAME, iborLegConventionName));
        }
        final IborIndexConvention iborIndexConvention = _conventionSource.getConvention(IborIndexConvention.class, iborLegConvention.getIborIndexConvention());
        final Frequency freqIbor = swapLeg.getFrequency();
        final Period tenorIbor = getTenor(freqIbor);
        final int spotLag = iborIndexConvention.getSettlementDays();
        final DayCount dayCount = swapLeg.getDayCount();
        final BusinessDayConvention businessDayConvention = swapLeg.getBusinessDayConvention();
        final double notional = interestRateNotional.getAmount();
        final IborIndex iborIndex = new IborIndex(currency, tenorIbor, spotLag, iborIndexConvention.getDayCount(), iborIndexConvention.getBusinessDayConvention(),
            iborIndexConvention.isIsEOM(), iborIndexConvention.getName());
        if (swapLeg instanceof FloatingSpreadIRLeg) {
          final FloatingSpreadIRLeg spread = (FloatingSpreadIRLeg) swapLeg;
          return AnnuityCouponIborSpreadDefinition.from(effectiveDate, maturityDate, tenorIbor, notional, iborIndex, isPayer, businessDayConvention, swapLeg.isEom(), dayCount,
              spread.getSpread(), calendar);
        }
        return AnnuityCouponIborDefinition.from(effectiveDate, maturityDate, tenorIbor, notional, iborIndex, isPayer, businessDayConvention, swapLeg.isEom(), dayCount,
            calendar);
      }

      private AnnuityDefinition<? extends PaymentDefinition> getOISAnnuity(final FloatingInterestRateLeg swapLeg, final InterestRateNotional interestRateNotional,
          final Currency currency) {
        final String oisConventionName = getConventionName(currency, OIS_ON_LEG);
        final OISLegConvention oisConvention = _conventionSource.getConvention(OISLegConvention.class, ExternalId.of(SCHEME_NAME, oisConventionName));
        if (oisConvention == null) {
          throw new OpenGammaRuntimeException("Could not get OIS leg convention with the identifier " + ExternalId.of(SCHEME_NAME, oisConventionName));
        }
        final OvernightIndexConvention indexConvention = _conventionSource.getConvention(OvernightIndexConvention.class, oisConvention.getOvernightIndexConvention());
        if (indexConvention == null) {
          throw new OpenGammaRuntimeException("Could not get OIS index convention with the identifier " + oisConvention.getOvernightIndexConvention());
        }
        final String currencyString = currency.getCode();
        final Integer publicationLag = indexConvention.getPublicationLag();
        final Period paymentFrequency = getTenor(swapLeg.getFrequency());
        final IndexON index = new IndexON(indexConvention.getName(), currency, indexConvention.getDayCount(), publicationLag);
        final BusinessDayConvention businessDayConvention = swapLeg.getBusinessDayConvention();
        final double notional = interestRateNotional.getAmount();
        final int paymentLag = oisConvention.getPaymentLag();
        final boolean isEOM = oisConvention.isIsEOM();
        final Calendar indexCalendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, indexConvention.getRegionCalendar());
        if (swapLeg instanceof FloatingSpreadIRLeg) {
          final FloatingSpreadIRLeg spread = (FloatingSpreadIRLeg) swapLeg;
          return AnnuityCouponONSpreadDefinition.from(effectiveDate, maturityDate, notional, isPayer, index, paymentLag, indexCalendar, businessDayConvention, paymentFrequency, isEOM,
              spread.getSpread());
        }
        return AnnuityCouponONDefinition.from(effectiveDate, maturityDate, notional, isPayer, index, paymentLag, indexCalendar, businessDayConvention, paymentFrequency, isEOM);
      }

      private AnnuityDefinition<? extends PaymentDefinition> getCMSAnnuity(final FloatingInterestRateLeg swapLeg, final InterestRateNotional interestRateNotional,
          final Currency currency, final Calendar calendar) {
        if (swapLeg instanceof FloatingSpreadIRLeg) {
          throw new OpenGammaRuntimeException("Cannot create an annuity for a CMS leg with a spread");
        }
        final String tenorString = getTenorString(swapLeg.getFrequency());
        final String iborLegConventionName = getConventionName(currency, tenorString, IRS_IBOR_LEG);
        final VanillaIborLegConvention iborLegConvention = _conventionSource.getConvention(VanillaIborLegConvention.class,
            ExternalId.of(SCHEME_NAME, getConventionName(currency, tenorString, IRS_IBOR_LEG)));
        if (iborLegConvention == null) {
          throw new OpenGammaRuntimeException("Could not get Ibor leg convention with the identifier " + ExternalId.of(SCHEME_NAME, iborLegConventionName));
        }
        final IborIndexConvention iborIndexConvention = _conventionSource.getConvention(IborIndexConvention.class, iborLegConvention.getIborIndexConvention());
        final String swapIndexConventionName = getConventionName(currency, tenorString, SWAP_INDEX);
        final SwapIndexConvention swapIndexConvention = _conventionSource.getConvention(SwapIndexConvention.class, ExternalId.of(SCHEME_NAME, swapIndexConventionName));
        if (swapIndexConvention == null) {
          throw new OpenGammaRuntimeException("Could not get swap index convention with the identifier " + ExternalId.of(SCHEME_NAME, swapIndexConventionName));
        }
        final SwapConvention underlyingSwapConvention = _conventionSource.getConvention(SwapConvention.class, swapIndexConvention.getSwapConvention());
        if (underlyingSwapConvention == null) {
          throw new OpenGammaRuntimeException("Could not get swap convention with the identifier " + swapIndexConvention.getSwapConvention());
        }
        final SwapFixedLegConvention payLegConvention = _conventionSource.getConvention(SwapFixedLegConvention.class, underlyingSwapConvention.getPayLegConvention());
        if (payLegConvention == null) {
          throw new OpenGammaRuntimeException("Could not get convention with the identifier " + underlyingSwapConvention.getPayLegConvention());
        }
        final VanillaIborLegConvention receiveLegConvention = _conventionSource.getConvention(VanillaIborLegConvention.class, underlyingSwapConvention.getReceiveLegConvention());
        if (receiveLegConvention == null) {
          throw new OpenGammaRuntimeException("Could not get convention with the identifier " + underlyingSwapConvention.getReceiveLegConvention());
        }
        final Frequency freqIbor = swapLeg.getFrequency();
        final Period tenorIbor = getTenor(freqIbor);
        final int spotLag = iborIndexConvention.getSettlementDays();
        final DayCount dayCount = swapLeg.getDayCount();
        final BusinessDayConvention businessDayConvention = swapLeg.getBusinessDayConvention();
        final double notional = interestRateNotional.getAmount();
        final IborIndex iborIndex = new IborIndex(currency, tenorIbor, spotLag, iborIndexConvention.getDayCount(), iborIndexConvention.getBusinessDayConvention(),
            iborIndexConvention.isIsEOM(), iborIndexConvention.getName());
        final Period fixedLegPaymentPeriod = payLegConvention.getPaymentTenor().getPeriod();
        final DayCount fixedLegDayCount = payLegConvention.getDayCount();
        final Period period = Period.ofYears(10); // TODO why is a variable field like this in IndexSwap? It's only used in one place in the entire analytics library.
        final IndexSwap swapIndex = new IndexSwap(fixedLegPaymentPeriod, fixedLegDayCount, iborIndex, period, calendar);
        return AnnuityCouponCMSDefinition.from(effectiveDate, maturityDate, notional, swapIndex, tenorIbor, dayCount, isPayer, calendar);
      }
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

    final Currency currency = FinancialSecurityUtils.getCurrency(security);
    final PriceIndexConvention indexConvention = _conventionSource.getConvention(PriceIndexConvention.class, getIds(currency, PRICE_INDEX));
    if (indexConvention == null) {
      throw new OpenGammaRuntimeException("Price index convention with id " + getIds(currency, PRICE_INDEX) + " was null");
    }
    final SwapFixedLegConvention fixedLegConvention = _conventionSource.getConvention(SwapFixedLegConvention.class, getIds(currency, IRS_FIXED_LEG));
    if (fixedLegConvention == null) {
      throw new OpenGammaRuntimeException("Swap fixed leg convention with id " + getIds(currency, IRS_FIXED_LEG) + " was null");
    }
    final InflationLegConvention inflationLegConvention = _conventionSource.getConvention(InflationLegConvention.class, getIds(currency, INFLATION_LEG));
    if (inflationLegConvention == null) {
      throw new OpenGammaRuntimeException("Inflation leg convention with id " + getIds(currency, INFLATION_LEG) + " was null");
    }
    final IndexPrice priceIndex = new IndexPrice(indexConvention.getName(), currency);
    final SwapLeg payLeg = security.getPayLeg();
    final SwapLeg receiveLeg = security.getReceiveLeg();
    final FixedInflationSwapLeg fixedLeg;
    final InflationIndexSwapLeg indexLeg;
    final boolean isPayer;
    if (payLeg instanceof FixedInflationSwapLeg && receiveLeg instanceof InflationIndexSwapLeg) {
      fixedLeg = (FixedInflationSwapLeg) payLeg;
      indexLeg = (InflationIndexSwapLeg) receiveLeg;
      isPayer = true;
    } else if (payLeg instanceof InflationIndexSwapLeg && receiveLeg instanceof FixedInflationSwapLeg) {
      fixedLeg = (FixedInflationSwapLeg) receiveLeg;
      indexLeg = (InflationIndexSwapLeg) payLeg;
      isPayer = false;
    } else {
      throw new OpenGammaRuntimeException("Can only convert fixed / float inflation swaps");
    }
    final int settlementDays = fixedLegConvention.getSettlementDays();
    final boolean isEOM = fixedLegConvention.isIsEOM();
    final DayCount fixedLegDayCount = fixedLeg.getDayCount();
    final BusinessDayConvention businessDayConvention = fixedLeg.getBusinessDayConvention();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, indexConvention.getRegion());
    final ZoneOffset zone = ZoneOffset.UTC; //TODO
    final Period paymentPeriod = getTenor(indexLeg.getFrequency());
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

    final Currency currency = FinancialSecurityUtils.getCurrency(security);
    final PriceIndexConvention indexConvention = _conventionSource.getConvention(PriceIndexConvention.class, getIds(currency, PRICE_INDEX));
    if (indexConvention == null) {
      throw new OpenGammaRuntimeException("Price index convention with id " + getIds(currency, PRICE_INDEX) + " was null");
    }
    final SwapFixedLegConvention fixedLegConvention = _conventionSource.getConvention(SwapFixedLegConvention.class, getIds(currency, IRS_FIXED_LEG));
    if (fixedLegConvention == null) {
      throw new OpenGammaRuntimeException("Swap fixed leg convention with id " + getIds(currency, IRS_FIXED_LEG) + " was null");
    }
    final InflationLegConvention inflationLegConvention = _conventionSource.getConvention(InflationLegConvention.class, getIds(currency, INFLATION_LEG));
    if (inflationLegConvention == null) {
      throw new OpenGammaRuntimeException("Inflation leg convention with id " + getIds(currency, INFLATION_LEG) + " was null");
    }
    final IndexPrice priceIndex = new IndexPrice(indexConvention.getName(), currency);
    final SwapLeg payLeg = security.getPayLeg();
    final SwapLeg receiveLeg = security.getReceiveLeg();
    final FixedInflationSwapLeg fixedLeg;
    final InflationIndexSwapLeg indexLeg;
    final boolean isPayer;
    if (payLeg instanceof FixedInflationSwapLeg && receiveLeg instanceof InflationIndexSwapLeg) {
      fixedLeg = (FixedInflationSwapLeg) payLeg;
      indexLeg = (InflationIndexSwapLeg) receiveLeg;
      isPayer = true;
    } else if (payLeg instanceof InflationIndexSwapLeg && receiveLeg instanceof FixedInflationSwapLeg) {
      fixedLeg = (FixedInflationSwapLeg) receiveLeg;
      indexLeg = (InflationIndexSwapLeg) payLeg;
      isPayer = false;
    } else {
      throw new OpenGammaRuntimeException("Can only convert fixed / float inflation swaps");
    }
    final int settlementDays = fixedLegConvention.getSettlementDays();
    final boolean isEOM = fixedLegConvention.isIsEOM();
    final BusinessDayConvention businessDayConvention = fixedLeg.getBusinessDayConvention();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, indexConvention.getRegion());
    final ZoneOffset zone = ZoneOffset.UTC; //TODO
   
    final int swapMaturityTenor = (int) Math.round(indexLeg.getDayCount().getDayCountFraction(security.getEffectiveDate(), security.getMaturityDate()));
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

        ? LocalDate.parse(desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_DATE))
        : now.toLocalDate();

    DepositConvention cashConvention = null;
    VanillaIborLegConvention floatLegConvention = null;
    SwapFixedLegConvention fixLegConvention = null;
    IborIndexConvention liborConvention = null;

    final int nNodes = specification.getNodes().size();
    final double[] marketDataForCurve = new double[nNodes];
    final ISDAInstrumentTypes[] instruments = new ISDAInstrumentTypes[nNodes];
    final Period[] tenors = new Period[nNodes];
    int k = 0;
    for (final CurveNodeWithIdentifier node : specification.getNodes()) {
      final Double marketData = snapshot.getDataPoint(node.getIdentifier());
      if (marketData == null) {
        throw new OpenGammaRuntimeException("Could not get market data for " + node.getIdentifier());
      }
      marketDataForCurve[k] = marketData;
      tenors[k] = node.getCurveNode().getResolvedMaturity().getPeriod();
      if (node.getCurveNode() instanceof CashNode) {
        instruments[k] = ISDAInstrumentTypes.MoneyMarket;
        final ExternalId cashConventionId = ((CashNode) node.getCurveNode()).getConvention();
        if (cashConvention == null) {
          cashConvention = conventionSource.getConvention(DepositConvention.class, cashConventionId);
        } else if (!cashConvention.getExternalIdBundle().contains(cashConventionId)) {
          throw new OpenGammaRuntimeException("Got 2 types of cash convention: " + cashConvention.getExternalIdBundle() + " " + cashConventionId);
        }
      } else if (node.getCurveNode() instanceof SwapNode) {
        instruments[k] = ISDAInstrumentTypes.Swap;
        final ExternalId payConventionId = ((SwapNode) node.getCurveNode()).getPayLegConvention();
        final Convention payConvention = conventionSource.getConvention(payConventionId);
        if (payConvention == null) {
          throw new OpenGammaRuntimeException("Convention '" + payConventionId + "' not found");
        }
        final ExternalId receiveConventionId = ((SwapNode) node.getCurveNode()).getReceiveLegConvention();
        final Convention receiveConvention = conventionSource.getConvention(receiveConventionId);
        if (receiveConvention == null) {
          throw new OpenGammaRuntimeException("Convention '" + receiveConventionId + "' not found");
        }
        if (payConvention instanceof VanillaIborLegConvention) {  // float leg
          if (floatLegConvention == null) {
            floatLegConvention = (VanillaIborLegConvention) payConvention;
          } else if (!floatLegConvention.getExternalIdBundle().contains(payConventionId)) {
            throw new OpenGammaRuntimeException("Got 2 types of float leg convention: " + payConvention.getExternalIdBundle() + " " + payConventionId);
          }
        } else if (payConvention instanceof SwapFixedLegConvention) {
          if (fixLegConvention == null) {
            fixLegConvention = (SwapFixedLegConvention) payConvention;
          } else if (!fixLegConvention.getExternalIdBundle().contains(payConventionId)) {
            throw new OpenGammaRuntimeException("Got 2 types of fixed leg convention: " + payConvention.getExternalIdBundle() + " " + payConventionId);
          }
        } else {
          throw new OpenGammaRuntimeException("Unexpected swap convention type: " + payConvention);
        }
        if (receiveConvention instanceof VanillaIborLegConvention) {  // float leg
          if (floatLegConvention == null) {
            floatLegConvention = (VanillaIborLegConvention) receiveConvention;
          } else if (!floatLegConvention.getExternalIdBundle().contains(receiveConventionId)) {
            throw new OpenGammaRuntimeException("Got 2 types of float leg convention: " + receiveConvention.getExternalIdBundle() + " " + receiveConventionId);
          }
        } else if (receiveConvention instanceof SwapFixedLegConvention) {
          if (fixLegConvention == null) {
            fixLegConvention = (SwapFixedLegConvention) receiveConvention;
          } else if (!fixLegConvention.getExternalIdBundle().contains(receiveConventionId)) {
            throw new OpenGammaRuntimeException("Got 2 types of fixed leg convention: " + receiveConvention.getExternalIdBundle() + " " + receiveConventionId);
          }
        } else {
          throw new OpenGammaRuntimeException("Unexpected swap convention type: " + receiveConvention);
        }
      } else {
        throw new OpenGammaRuntimeException("Can't handle node type " + node.getCurveNode().getClass().getSimpleName() + " at node " + node);
      }
      k++;
    }

    ArgumentChecker.notNull(cashConvention, "Cash convention");
    ArgumentChecker.notNull(floatLegConvention, "Floating leg convention");
    ArgumentChecker.notNull(fixLegConvention, "Fixed leg convention");
    liborConvention = conventionSource.getConvention(IborIndexConvention.class, floatLegConvention.getIborIndexConvention());
    ArgumentChecker.notNull(liborConvention, floatLegConvention.getIborIndexConvention().toString());

    final ISDACompliantYieldCurve yieldCurve = ISDACompliantYieldCurveBuild.build(spotDate, spotDate, instruments, tenors, marketDataForCurve, cashConvention.getDayCount(),
        fixLegConvention.getDayCount(), fixLegConvention.getPaymentTenor().getPeriod(), ACT_365, liborConvention.getBusinessDayConvention());

    final ValueProperties properties = desiredValue.getConstraints().copy()
        .with(ISDAFunctionConstants.ISDA_CURVE_DATE, spotDate.toString())
        .get();
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

    final DepositConvention depositConvention = new DepositConvention(depositConventionName, getIds(Currency.USD, DEPOSIT), ACT_360, MODIFIED_FOLLOWING, 2, true, Currency.USD, US);
    final DepositConvention depositONConvention = new DepositConvention(depositONConventionName, getIds(Currency.USD, DEPOSIT_ON), ACT_360, FOLLOWING, 0, false, Currency.USD, US);
   
    // Fixed Leg
    final String fixedLeg1YPayLagConventionName = getConventionName(Currency.USD, TENOR_STR_1Y, PAY_LAG + FIXED_LEG);
    final Convention fixedLeg1YPayLagConvention = new SwapFixedLegConvention(fixedLeg1YPayLagConventionName, getIds(Currency.USD, TENOR_STR_1Y, PAY_LAG + FIXED_LEG),
        Tenor.ONE_YEAR, ACT_360, MODIFIED_FOLLOWING, Currency.USD, US, 2, true, StubType.SHORT_START, false, 2);
    final String fixedLegShortPayLagConventionName = getConventionName(Currency.USD, TENOR_STR_SHORT, PAY_LAG + FIXED_LEG);
    final Convention fixedLegShortPayLagConvention = new SwapFixedLegConvention(fixedLegShortPayLagConventionName, getIds(Currency.USD, TENOR_STR_SHORT, PAY_LAG + FIXED_LEG),
        Tenor.ONE_YEAR, ACT_360, FOLLOWING, Currency.USD, US, 2, false, StubType.SHORT_START, false, 2);
    // Fixed 1Y- ON compounded 1Y
    final String oisFixedLegConventionName = getConventionName(Currency.USD, OIS_FIXED_LEG);
    final String oisONLegConventionName = getConventionName(Currency.USD, OIS_ON_LEG);
    final Convention oisFixedLegConvention = new SwapFixedLegConvention(oisFixedLegConventionName, getIds(Currency.USD, OIS_FIXED_LEG),
        Tenor.ONE_YEAR, ACT_360, MODIFIED_FOLLOWING, Currency.USD, US, 2, true, StubType.SHORT_START, false, 2);
    final Convention oisONLegConvention = new OISLegConvention(oisONLegConventionName, getIds(Currency.USD, OIS_ON_LEG), overnightConventionId,
        Tenor.ONE_YEAR, MODIFIED_FOLLOWING, 2, false, StubType.NONE, false, 2);
   
    // ON Compounded 3M
    final String onCmp3MLegConventionName = getConventionName(Currency.USD, TENOR_STR_3M, ON_CMP_LEG);
    final Convention onCmp3MLegConvention = new OISLegConvention(onCmp3MLegConventionName, getIds(Currency.USD, TENOR_STR_3M, ON_CMP_LEG), overnightConventionId,
        Tenor.THREE_MONTHS, MODIFIED_FOLLOWING, 2, false, StubType.SHORT_START, false, 2);
   
    // Ibor legs - no payment delay
    final String irsFixedLegConventionName = getConventionName(Currency.USD, IRS_FIXED_LEG);
    final Convention irsFixedLegConvention = new SwapFixedLegConvention(irsFixedLegConventionName, getIds(Currency.USD, IRS_FIXED_LEG),
        Tenor.SIX_MONTHS, THIRTY_360, MODIFIED_FOLLOWING, Currency.USD, NYLON, 2, true, StubType.SHORT_START, false, 0);
   
    final String liborLeg1MConventionName = getConventionName(Currency.USD, TENOR_STR_1M, IRS_IBOR_LEG);
    final Convention liborLeg1MConvention = new VanillaIborLegConvention(liborLeg1MConventionName, getIds(Currency.USD, TENOR_STR_1M, IRS_IBOR_LEG),
        liborConventionId, true, Interpolator1DFactory.LINEAR, Tenor.ONE_MONTH, 2, true, StubType.SHORT_START, false, 0);
    final String liborLeg3MConventionName = getConventionName(Currency.USD, TENOR_STR_3M, IRS_IBOR_LEG);
    final Convention liborLeg3MConvention = new VanillaIborLegConvention(liborLeg3MConventionName, getIds(Currency.USD, TENOR_STR_3M, IRS_IBOR_LEG),
        liborConventionId, true, Interpolator1DFactory.LINEAR, Tenor.THREE_MONTHS, 2, true, StubType.SHORT_START, false, 0);
    final String liborLeg6MConventionName = getConventionName(Currency.USD, TENOR_STR_6M, IRS_IBOR_LEG);
    final Convention liborLeg6MConvention = new VanillaIborLegConvention(liborLeg6MConventionName, getIds(Currency.USD, TENOR_STR_6M, IRS_IBOR_LEG),
        liborConventionId, true, Interpolator1DFactory.LINEAR, Tenor.SIX_MONTHS, 2, true, StubType.SHORT_START, false, 0);
    final String liborLeg12MConventionName = getConventionName(Currency.USD, TENOR_STR_12M, IRS_IBOR_LEG);
    final Convention liborLeg12MConvention = new VanillaIborLegConvention(liborLeg12MConventionName, getIds(Currency.USD, TENOR_STR_12M, IRS_IBOR_LEG),
        liborConventionId, true, Interpolator1DFactory.LINEAR, Tenor.TWELVE_MONTHS, 2, true, StubType.SHORT_START, false, 0);

    // Ibor legs - with payment delay
    final String liborLeg3MPayLagConventionName = getConventionName(Currency.USD, TENOR_STR_3M, PAY_LAG + IBOR_LEG);
    final Convention liborLeg3MPayLagConvention = new VanillaIborLegConvention(liborLeg3MPayLagConventionName, getIds(Currency.USD, TENOR_STR_3M, PAY_LAG + IBOR_LEG),
        liborConventionId, true, Interpolator1DFactory.LINEAR, Tenor.THREE_MONTHS, 2, true, StubType.NONE, false, 2);

    // Ibor legs - compounded
    final String liborLeg1MComp3MConventionName = getConventionName(Currency.USD, TENOR_STR_1M + " x " + TENOR_STR_3M, IBOR_CMP_LEG); // "USD 1M x 3M Comp Ibor Leg" 
    final Convention liborLeg1MComp3MConvention = new CompoundingIborLegConvention(liborLeg1MComp3MConventionName, getIds(Currency.USD, TENOR_STR_1M + " x " + TENOR_STR_3M, IBOR_CMP_LEG),
        liborConventionId, Tenor.THREE_MONTHS, CompoundingType.FLAT_COMPOUNDING, Tenor.ONE_MONTH, StubType.SHORT_START, 2, false, StubType.LONG_START, false, 0);
   
    // Swaps
    final Convention swapConvention = new SwapConvention("USD Swap", ExternalIdBundle.of(ExternalId.of(SCHEME_NAME, "USD Swap")),
        ExternalId.of(SCHEME_NAME, getConventionName(Currency.USD, IRS_FIXED_LEG)),
        ExternalId.of(SCHEME_NAME, getConventionName(Currency.USD, TENOR_STR_3M, IRS_IBOR_LEG)));
    final Convention swapIndexConvention = new SwapIndexConvention(swapIndexConventionName, getIds(Currency.USD, SWAP_INDEX), LocalTime.of(11, 0), ExternalId.of(SCHEME_NAME, "USD Swap"));
   
    // Futures (for ED-LIBOR3M and EM-LIBOR1M)
    final String quartFutureConventionName = getConventionName(Currency.USD, STIR_FUTURES + QUARTERLY);
    final Convention quartSTIRFutureConvention = new InterestRateFutureConvention(quartFutureConventionName, ExternalIdBundle.of(ExternalId.of(SCHEME_NAME, quartFutureConventionName)),
        ExternalId.of(ExchangeTradedInstrumentExpiryCalculator.SCHEME, IMMFutureAndFutureOptionQuarterlyExpiryCalculator.NAME), US, liborConventionId);
    final String serialFutureConventionName = getConventionName(Currency.USD, STIR_FUTURES + SERIAL);
    final Convention serialSTIRFutureConvention = new InterestRateFutureConvention(serialFutureConventionName, ExternalIdBundle.of(ExternalId.of(SCHEME_NAME, serialFutureConventionName)),
        ExternalId.of(ExchangeTradedInstrumentExpiryCalculator.SCHEME, IMMFutureAndFutureOptionMonthlyExpiryCalculator.NAME), US, liborConventionId);
   
    final Convention fedFundsConvention = new FederalFundsFutureConvention(fedFundFutureConventionName, ExternalIdBundle.of(ExternalId.of(SCHEME_NAME, FED_FUNDS_FUTURE)),
        ExternalId.of(ExchangeTradedInstrumentExpiryCalculator.SCHEME, FedFundFutureAndFutureOptionMonthlyExpiryCalculator.NAME), US, overnightConventionId, 5000000);
    final Convention cmsDeliverableSwapFutureConvention = new DeliverablePriceQuotedSwapFutureConvention(cmeDeliverableSwapFutureConventionName,
        ExternalIdBundle.of(SCHEME_NAME, CME_DELIVERABLE_SWAP_FUTURE), ExternalId.of(ExchangeTradedInstrumentExpiryCalculator.SCHEME,
            IMMFutureAndFutureOptionQuarterlyExpiryCalculator.NAME), US, liborConventionId, 100000);
    // Inflation
    final PriceIndexConvention priceIndexConvention = new PriceIndexConvention(priceIndexName, getIds(Currency.USD, PRICE_INDEX), Currency.USD, US,
        ExternalSchemes.bloombergTickerSecurityId("CPURNSA Index"));
    final Convention inflationConvention = new InflationLegConvention(inflationConventionName, getIds(Currency.USD, INFLATION_LEG), MODIFIED_FOLLOWING, ACT_360, false, 3, 2,
        priceIndexId);
    // US Treasury: Synthetic swaps to represent bonds, using yield
    final String fixedLegGovtConventionName = getConventionName(Currency.USD, TENOR_STR_6M, GOVT + FIXED_LEG);
    final Convention fixedLegGovtConvention = new SwapFixedLegConvention(fixedLegGovtConventionName, getIds(Currency.USD, TENOR_STR_6M, GOVT + FIXED_LEG),
        Tenor.SIX_MONTHS, ACT_ACT, FOLLOWING, Currency.USD, US, 2, false, StubType.SHORT_START, false, 0);
    final String liborLegGovtConventionName = getConventionName(Currency.USD, TENOR_STR_3M, GOVT + IBOR_LEG);
    final Convention liborLegGovtConvention = new VanillaIborLegConvention(liborLegGovtConventionName, getIds(Currency.USD, TENOR_STR_3M, GOVT + IBOR_LEG),
        liborConventionId, true, Interpolator1DFactory.LINEAR, Tenor.THREE_MONTHS, 2, false, StubType.NONE, false, 0);
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

    // Deposit
    final String depositONConventionName = getConventionName(Currency.AUD, DEPOSIT_ON);
    final DepositConvention depositONConvention = new DepositConvention(depositONConventionName, getIds(Currency.AUD, DEPOSIT_ON), ACT_365, FOLLOWING, 0, false, Currency.AUD, AU);
    // Fixed Legs
    final String fixedLeg3MConventionName = getConventionName(Currency.AUD, TENOR_STR_3M, FIXED_LEG);
    final Convention fixedLeg3MConvention = new SwapFixedLegConvention(fixedLeg3MConventionName, getIds(Currency.AUD, TENOR_STR_3M, FIXED_LEG),
        Tenor.THREE_MONTHS, ACT_365, MODIFIED_FOLLOWING, Currency.AUD, AU, 2, true, StubType.SHORT_START, false, 0);
    final String fixedLeg6MConventionName = getConventionName(Currency.AUD, TENOR_STR_6M, FIXED_LEG);
    final Convention fixedLeg6MConvention = new SwapFixedLegConvention(fixedLeg6MConventionName, getIds(Currency.AUD, TENOR_STR_6M, FIXED_LEG),
        Tenor.SIX_MONTHS, ACT_365, MODIFIED_FOLLOWING, Currency.AUD, AU, 2, true, StubType.SHORT_START, false, 0);
    final String fixedLeg1YPayLagConventionName = getConventionName(Currency.AUD, TENOR_STR_1Y, PAY_LAG + FIXED_LEG);
    final Convention fixedLeg1YPayLagConvention = new SwapFixedLegConvention(fixedLeg1YPayLagConventionName, getIds(Currency.AUD, TENOR_STR_1Y, PAY_LAG + FIXED_LEG),
        Tenor.ONE_YEAR, ACT_365, MODIFIED_FOLLOWING, Currency.AUD, AU, 2, true, StubType.SHORT_START, false, 2);
    // BBSW Legs
    final String bbsw3MLegConventionName = getConventionName(Currency.AUD, TENOR_STR_3M, BBSW_LEG);
    final Convention bbsw3MLegConvention = new VanillaIborLegConvention(bbsw3MLegConventionName, getIds(Currency.AUD, TENOR_STR_3M, BBSW_LEG),
        bbswConventionId, true, Interpolator1DFactory.LINEAR, Tenor.THREE_MONTHS, 2, true, StubType.SHORT_START, false, 0);
View Full Code Here

Examples of com.opengamma.financial.convention.SwapFixedLegConvention

    assertEquals(convention, cycleObject(SwapConvention.class, convention));
  }

  @Test
  public void testSwapFixedLegConvention() {
    final SwapFixedLegConvention convention = new SwapFixedLegConvention("EUR Fixed Leg", ExternalIdBundle.of(InMemoryConventionBundleMaster.simpleNameSecurityId("EUR Fixed Leg")),
        Tenor.THREE_MONTHS, DayCountFactory.INSTANCE.getDayCount("30/360"), BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Following"),
        Currency.EUR, ExternalId.of("Test", "EU"), 2, true, StubType.LONG_END, false, 3);
    convention.setUniqueId(UniqueId.of("Test", "123"));
    assertEquals(convention, cycleObject(SwapFixedLegConvention.class, convention));
  }
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.