Package com.opengamma.financial.convention.frequency

Examples of com.opengamma.financial.convention.frequency.Frequency


  public CapFloorSecurity createSecurity(final OperationContext context, CapFloorSecurityBean bean) {
   
    ZonedDateTime startDate = zonedDateTimeBeanToDateTimeWithZone(bean.getStartDate());
    ZonedDateTime maturityDate = zonedDateTimeBeanToDateTimeWithZone(bean.getMaturityDate());
    ExternalId underlyingIdentifier = externalIdBeanToExternalId(bean.getUnderlyingIdentifier());
    Frequency frequency = frequencyBeanToFrequency(bean.getFrequency());
    Currency currency = currencyBeanToCurrency(bean.getCurrency());
    DayCount dayCount = dayCountBeanToDayCount(bean.getDayCount());
    return new CapFloorSecurity(startDate,
        maturityDate,
        bean.getNotional(),
View Full Code Here


    final ZonedDateTime swaptionExpiry = tradeDate.plus(expiryPeriod).atStartOfDay().atZone(ZoneOffset.UTC);
    final ZonedDateTime swapMaturity = swaptionExpiry.plus(maturity.getPeriod());
    final double amount = 100000 * (1 + random.nextInt(30));
    final InterestRateNotional notional = new InterestRateNotional(ccy, amount);
    final double rate = getSwapRate(ccy, tradeDate, maturity) * (1 + ((random.nextDouble() - 0.5) / 30.));
    final Frequency frequency = ccy.equals(Currency.USD) ? PeriodFrequency.QUARTERLY : PeriodFrequency.SEMI_ANNUAL;
    final SwapLeg fixedLeg = new FixedInterestRateLeg(DAY_COUNT, PeriodFrequency.SEMI_ANNUAL, region, BDC, notional, false, rate);
    final SwapLeg floatLeg = new FloatingInterestRateLeg(DAY_COUNT, frequency, region, BDC, notional, false, floatingRate, FloatingRateType.IBOR);
    final SwapLeg payLeg, receiveLeg;
    final String swapName, swaptionName;
    final boolean isLong = random.nextBoolean();
View Full Code Here

  /**
   * Tests the adjusted date schedule. Reviewed 22-Feb-2012.
   */
  public void adjustedDateSchedule2() {
    final Period m6 = Period.ofMonths(6);
    final Frequency semi = PeriodFrequency.SEMI_ANNUAL;
    final Period y5 = Period.ofYears(5);
    final ZonedDateTime midMonth = DateUtils.getUTCDate(2012, 1, 19);
    final ZonedDateTime[] midMonthUnadjusted = ScheduleCalculator.getUnadjustedDateSchedule(midMonth, midMonth.plus(y5), m6, false, false);
    final ZonedDateTime[] midMonthModFolExpected = ScheduleCalculator.getAdjustedDateSchedule(midMonthUnadjusted, MOD_FOL, CALENDAR, false);
    final ZonedDateTime[] midMonthModFolDate = ScheduleCalculator.getAdjustedDateSchedule(midMonth, midMonth.plus(y5), m6, false, false, MOD_FOL, CALENDAR, false);
View Full Code Here

    ScheduleCalculator.getUnadjustedDateSchedule(DateUtils.getUTCDate(2008, 6, 1), DateUtils.getUTCDate(2010, 7, 1), DateUtils.getUTCDate(2009, 6, 1), PeriodFrequency.ANNUAL);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testWrongFrequencyType() {
    ScheduleCalculator.getUnadjustedDateSchedule(DateUtils.getUTCDate(2010, 6, 1), DateUtils.getUTCDate(2010, 7, 1), DateUtils.getUTCDate(2010, 8, 1), new Frequency() {

      @Override
      public String getConventionName() {
        return null;
      }
View Full Code Here

    ArgumentChecker.notNull(conventionMaster, "convention master");
    final BusinessDayConvention modified = BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Modified Following");
    final BusinessDayConvention following = BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Following");
    final DayCount act360 = DayCountFactory.INSTANCE.getDayCount("Actual/360");
    final DayCount thirty360 = DayCountFactory.INSTANCE.getDayCount("30/360");
    final Frequency annual = PeriodFrequency.ANNUAL;
    final Frequency semiAnnual = SimpleFrequencyFactory.INSTANCE.getFrequency(Frequency.SEMI_ANNUAL_NAME);
    final Frequency quarterly = SimpleFrequencyFactory.INSTANCE.getFrequency(Frequency.QUARTERLY_NAME);

    final ExternalId usgb = ExternalSchemes.financialRegionId("US+GB");
    final ExternalId us = ExternalSchemes.financialRegionId("US");

    final ConventionBundleMasterUtils utils = new ConventionBundleMasterUtils(conventionMaster);

    // LIBOR
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US00O/N Index"), simpleNameSecurityId("USD LIBOR O/N")),
        "USD LIBOR O/N", act360, following, Period.ofDays(1), 0, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US00T/N Index"), simpleNameSecurityId("USD LIBOR T/N")),
        "USD LIBOR T/N", act360, following, Period.ofDays(1), 1, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0001W Index"), simpleNameSecurityId("USD LIBOR 1w"),
        tullettPrebonSecurityId("ASLIBUSD1WL")), "USD LIBOR 1w", act360, following, Period.ofDays(7), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0002W Index"), simpleNameSecurityId("USD LIBOR 2w"),
        tullettPrebonSecurityId("ASLIBUSD2WL")), "USD LIBOR 2w", act360, following, Period.ofDays(14), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0001M Index"), simpleNameSecurityId("USD LIBOR 1m"),
        tullettPrebonSecurityId("ASLIBUSD01L")), "USD LIBOR 1m", act360, modified, Period.ofMonths(1), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0002M Index"), simpleNameSecurityId("USD LIBOR 2m"),
        tullettPrebonSecurityId("ASLIBUSD02L")), "USD LIBOR 2m", act360, modified, Period.ofMonths(2), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0003M Index"), simpleNameSecurityId("USD LIBOR 3m"),
        ExternalSchemes.ricSecurityId("USD3MFSR="), tullettPrebonSecurityId("ASLIBUSD03L")),
        "USD LIBOR 3m", act360, modified, Period.ofMonths(3), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0004M Index"), simpleNameSecurityId("USD LIBOR 4m"),
        tullettPrebonSecurityId("ASLIBUSD04L")), "USD LIBOR 4m", act360, modified, Period.ofMonths(4), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0005M Index"), simpleNameSecurityId("USD LIBOR 5m"),
        tullettPrebonSecurityId("ASLIBUSD05L")), "USD LIBOR 5m", act360, modified, Period.ofMonths(5), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0006M Index"), simpleNameSecurityId("USD LIBOR 6m"),
        tullettPrebonSecurityId("ASLIBUSD06L")), "USD LIBOR 6m", act360, modified, Period.ofMonths(6), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0007M Index"), simpleNameSecurityId("USD LIBOR 7m"),
        tullettPrebonSecurityId("ASLIBUSD07L")), "USD LIBOR 7m", act360, modified, Period.ofMonths(7), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0008M Index"), simpleNameSecurityId("USD LIBOR 8m"),
        tullettPrebonSecurityId("ASLIBUSD08L")), "USD LIBOR 8m", act360, modified, Period.ofMonths(8), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0009M Index"), simpleNameSecurityId("USD LIBOR 9m"),
        tullettPrebonSecurityId("ASLIBUSD09L")), "USD LIBOR 9m", act360, modified, Period.ofMonths(9), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0010M Index"), simpleNameSecurityId("USD LIBOR 10m"),
        tullettPrebonSecurityId("ASLIBUSD10L")), "USD LIBOR 10m", act360, modified, Period.ofMonths(10), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0011M Index"), simpleNameSecurityId("USD LIBOR 11m"),
        tullettPrebonSecurityId("ASLIBUSD11L")), "USD LIBOR 11m", act360, modified, Period.ofMonths(11), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("US0012M Index"), simpleNameSecurityId("USD LIBOR 12m"),
        tullettPrebonSecurityId("ASLIBUSD12L")), "USD LIBOR 12m", act360, modified, Period.ofMonths(12), 2, false, us);

    //TODO need to check that these are right for deposit rates
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR1T Curncy"), simpleNameSecurityId("USD DEPOSIT 1d")),
        "USD DEPOSIT 1d", act360, following, Period.ofDays(1), 0, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR2T Curncy"), simpleNameSecurityId("USD DEPOSIT 2d")),
        "USD DEPOSIT 2d", act360, following, Period.ofDays(1), 1, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR3T Curncy"), simpleNameSecurityId("USD DEPOSIT 3d")),
        "USD DEPOSIT 3d", act360, following, Period.ofDays(1), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR1Z Curncy"), simpleNameSecurityId("USD DEPOSIT 1w"),
        tullettPrebonSecurityId("ASDEPUSDSPT01W"), icapSecurityId("USD_1W")), "USD DEPOSIT 1w", act360, following, Period.ofDays(7), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR2Z Curncy"), simpleNameSecurityId("USD DEPOSIT 2w"),
        tullettPrebonSecurityId("ASDEPUSDSPT02W"), icapSecurityId("USD_2W")), "USD DEPOSIT 2w", act360, following, Period.ofDays(14), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR3Z Curncy"), simpleNameSecurityId("USD DEPOSIT 3w"),
        tullettPrebonSecurityId("ASDEPUSDSPT03W"), icapSecurityId("USD_3W")), "USD DEPOSIT 3w", act360, following, Period.ofDays(21), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRA Curncy"), simpleNameSecurityId("USD DEPOSIT 1m"),
        tullettPrebonSecurityId("ASDEPUSDSPT01M"), icapSecurityId("USD_1M")), "USD DEPOSIT 1m", act360, following, Period.ofMonths(1), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRB Curncy"), simpleNameSecurityId("USD DEPOSIT 2m"),
        tullettPrebonSecurityId("ASDEPUSDSPT02M"), icapSecurityId("USD_2M")), "USD DEPOSIT 2m", act360, following, Period.ofMonths(2), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRC Curncy"), simpleNameSecurityId("USD DEPOSIT 3m"),
        tullettPrebonSecurityId("ASDEPUSDSPT03M"), icapSecurityId("USD_3M")), "USD DEPOSIT 3m", act360, following, Period.ofMonths(3), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRD Curncy"), simpleNameSecurityId("USD DEPOSIT 4m"),
        tullettPrebonSecurityId("ASDEPUSDSPT04M"), icapSecurityId("USD_4M")), "USD DEPOSIT 4m", act360, following, Period.ofMonths(4), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRE Curncy"), simpleNameSecurityId("USD DEPOSIT 5m"),
        tullettPrebonSecurityId("ASDEPUSDSPT05M"), icapSecurityId("USD_5M")), "USD DEPOSIT 5m", act360, following, Period.ofMonths(5), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRF Curncy"), simpleNameSecurityId("USD DEPOSIT 6m"),
        tullettPrebonSecurityId("ASDEPUSDSPT06M"), icapSecurityId("USD_6M")), "USD DEPOSIT 6m", act360, following, Period.ofMonths(6), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRG Curncy"), simpleNameSecurityId("USD DEPOSIT 7m"),
        tullettPrebonSecurityId("ASDEPUSDSPT07M"), icapSecurityId("USD_7M")), "USD DEPOSIT 7m", act360, following, Period.ofMonths(7), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRH Curncy"), simpleNameSecurityId("USD DEPOSIT 8m"),
        tullettPrebonSecurityId("ASDEPUSDSPT08M"), icapSecurityId("USD_8M")), "USD DEPOSIT 8m", act360, following, Period.ofMonths(8), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRI Curncy"), simpleNameSecurityId("USD DEPOSIT 9m"),
        tullettPrebonSecurityId("ASDEPUSDSPT09M"), icapSecurityId("USD_9M")), "USD DEPOSIT 9m", act360, following, Period.ofMonths(9), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRJ Curncy"), simpleNameSecurityId("USD DEPOSIT 10m"),
        tullettPrebonSecurityId("ASDEPUSDSPT10M"), icapSecurityId("USD_10M")), "USD DEPOSIT 10m", act360, following, Period.ofMonths(10), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDRK Curncy"), simpleNameSecurityId("USD DEPOSIT 11m"),
        tullettPrebonSecurityId("ASDEPUSDSPT11M"), icapSecurityId("USD_11M")), "USD DEPOSIT 11m", act360, following, Period.ofMonths(11), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR1 Curncy"), simpleNameSecurityId("USD DEPOSIT 1y"),
        tullettPrebonSecurityId("ASDEPUSDSPT12M"), icapSecurityId("USD_12M")), "USD DEPOSIT 1y", act360, following, Period.ofYears(1), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR2 Curncy"), simpleNameSecurityId("USD DEPOSIT 2y")),
        "USD DEPOSIT 2y", act360, following, Period.ofYears(2), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR3 Curncy"), simpleNameSecurityId("USD DEPOSIT 3y")),
        "USD DEPOSIT 3y", act360, following, Period.ofYears(3), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR4 Curncy"), simpleNameSecurityId("USD DEPOSIT 4y")),
        "USD DEPOSIT 4y", act360, following, Period.ofYears(4), 2, false, us);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("USDR5 Curncy"), simpleNameSecurityId("USD DEPOSIT 5y")),
        "USD DEPOSIT 5y", act360, following, Period.ofYears(5), 2, false, us);

    //TODO with improvement in settlement days definition (i.e. including holiday and adjustment) change this
    // should be 2, LON, following
    // holiday for swap should be NY+LON

    final DayCount swapFixedDayCount = thirty360;
    final BusinessDayConvention swapFixedBusinessDay = modified;
    final Frequency swapFixedPaymentFrequency = semiAnnual;
    final DayCount swapFloatDayCount = act360;
    final BusinessDayConvention swapFloatBusinessDay = modified;
    final Frequency swapFloatPaymentFrequency = quarterly;

    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("USD_SWAP")), "USD_SWAP", swapFixedDayCount, swapFixedBusinessDay,
        swapFixedPaymentFrequency, 2, usgb, swapFloatDayCount, swapFloatBusinessDay, swapFloatPaymentFrequency, 2, simpleNameSecurityId("USD LIBOR 3m"),
        usgb, true);
View Full Code Here

      final int swapYears = 1 + rng.nextInt(28);
      final ZonedDateTime swapMaturity = swaptionExpiry.plusMonths(swapYears);
      final double amount = 100000 * (1 + rng.nextInt(30));
      final InterestRateNotional notional = new InterestRateNotional(currency, amount);
      final double rate = swapYears * rng.nextDouble() / 500;
      final Frequency frequency = currency.equals(Currency.USD) ? PeriodFrequency.QUARTERLY : PeriodFrequency.SEMI_ANNUAL;
      final SwapLeg fixedLeg = new FixedInterestRateLeg(DAY_COUNT, PeriodFrequency.SEMI_ANNUAL, region, BDC, notional, false, rate);
      final SwapLeg floatLeg = new FloatingInterestRateLeg(DAY_COUNT, frequency, region, BDC, notional, false, floatingRate, FloatingRateType.IBOR);
      final SwapLeg payLeg, receiveLeg;
      final String swapName, swaptionName;
      final boolean isLong = rng.nextBoolean();
View Full Code Here

    final FloatingInterestRateLeg iborLeg = (FloatingInterestRateLeg) (payFixed ? receiveLeg : payLeg);
    final ExternalId regionId = payLeg.getRegionId();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
    final Currency currency = ((InterestRateNotional) payLeg.getNotional()).getCurrency();
    final IborIndexConvention iborIndexConvention = getIborLegConvention(currency);
    final Frequency freqIbor = iborLeg.getFrequency();
    final Period tenorIbor = getTenor(freqIbor);
    final int spotLag = iborIndexConvention.getSettlementDays();
    final IborIndex indexIbor = new IborIndex(currency, tenorIbor, spotLag, iborIndexConvention.getDayCount(),
        iborIndexConvention.getBusinessDayConvention(), iborIndexConvention.isIsEOM(), iborIndexConvention.getName());
    final Frequency freqFixed = fixedLeg.getFrequency();
    final Period tenorFixed = getTenor(freqFixed);
    final double fixedLegNotional = ((InterestRateNotional) fixedLeg.getNotional()).getAmount();
    final double iborLegNotional = ((InterestRateNotional) iborLeg.getNotional()).getAmount();
    if (hasSpread) {
      final double spread = ((FloatingSpreadIRLeg) iborLeg).getSpread();
View Full Code Here

        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();
View Full Code Here

    Validate.notNull(capFloorCMSSpreadSecurity, "cap/floor security");
    final ZonedDateTime startDate = capFloorCMSSpreadSecurity.getStartDate();
    final ZonedDateTime endDate = capFloorCMSSpreadSecurity.getMaturityDate();
    final double notional = capFloorCMSSpreadSecurity.getNotional();
    final Currency currency = capFloorCMSSpreadSecurity.getCurrency();
    final Frequency payFreq = capFloorCMSSpreadSecurity.getFrequency();
    // FIXME: convert frequency to period in a better way
    final Period tenorPayment = getTenor(payFreq);
    final ExternalId[] swapIndexId = new ExternalId[2];
    swapIndexId[0] = capFloorCMSSpreadSecurity.getLongId();
    swapIndexId[1] = capFloorCMSSpreadSecurity.getShortId();
View Full Code Here

    ScheduleFactory.getSchedule(START1, END1, null, true, false, false);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testBadFrequency1() {
    final Frequency frequency = new Frequency() {

      @Override
      public String getConventionName() {
        return null;
      }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.convention.frequency.Frequency

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.