Package com.opengamma.financial.convention

Examples of com.opengamma.financial.convention.Convention


    return currencies;
  }

  @Override
  public Set<Currency> visitSwapNode(final SwapNode node) {
    final Convention payConvention = _conventionSource.getConvention(node.getPayLegConvention());
    if (payConvention == null) {
      throw new OpenGammaRuntimeException("Could not get pay convention with id " + node.getPayLegConvention());
    }
    final Convention receiveConvention = _conventionSource.getConvention(node.getReceiveLegConvention());
    if (receiveConvention == null) {
      throw new OpenGammaRuntimeException("Could not get receive convention with id " + node.getReceiveLegConvention());
    }
    final Set<Currency> currencies = new HashSet<>(getCurrencies(payConvention));
    currencies.addAll(getCurrencies(receiveConvention));
View Full Code Here


    return currencies;
  }

  @Override
  public Set<Currency> visitZeroCouponInflationNode(final ZeroCouponInflationNode node) {
    final Convention inflationLegConvention = _conventionSource.getConvention(node.getInflationLegConvention());
    if (inflationLegConvention == null) {
      throw new OpenGammaRuntimeException("Could not get inflation leg convention with id " + node.getInflationLegConvention());
    }
    if (!(inflationLegConvention instanceof InflationLegConvention)) {
      throw new OpenGammaRuntimeException("Type of convention " + inflationLegConvention + " was not InflationLegConvention");
    }
    final Convention priceIndexConvention = _conventionSource.getConvention(((InflationLegConvention) inflationLegConvention).getPriceIndexConvention());
    if (priceIndexConvention == null) {
      throw new OpenGammaRuntimeException("Could not get price index convention with id " + ((InflationLegConvention) inflationLegConvention).getPriceIndexConvention());
    }
    return getCurrencies(priceIndexConvention);
  }
View Full Code Here

  }

  protected Set<Currency> getCurrencies(final Convention convention) {
    ArgumentChecker.notNull(convention, "convention");
    if (convention instanceof CMSLegConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((CMSLegConvention) convention).getSwapIndexConvention());
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + ((CMSLegConvention) convention).getSwapIndexConvention());
      }
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof CompoundingIborLegConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((CompoundingIborLegConvention) convention).getIborIndexConvention());
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + ((CompoundingIborLegConvention) convention).getIborIndexConvention());
      }
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof DepositConvention) {
      return Collections.singleton(((DepositConvention) convention).getCurrency());
    }
    if (convention instanceof IborIndexConvention) {
      return Collections.singleton(((IborIndexConvention) convention).getCurrency());
    }
    if (convention instanceof InterestRateFutureConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((InterestRateFutureConvention) convention).getIndexConvention());
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof DeliverablePriceQuotedSwapFutureConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((DeliverablePriceQuotedSwapFutureConvention) convention).getSwapConvention());
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof FederalFundsFutureConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((FederalFundsFutureConvention) convention).getIndexConvention());
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof InterestRateFutureConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((InterestRateFutureConvention) convention).getIndexConvention());
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof OISLegConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((OISLegConvention) convention).getOvernightIndexConvention());
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + ((OISLegConvention) convention).getOvernightIndexConvention());
      }
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof OvernightIndexConvention) {
      return Collections.singleton(((OvernightIndexConvention) convention).getCurrency());
    }
    if (convention instanceof PriceIndexConvention) {
      return Collections.singleton(((PriceIndexConvention) convention).getCurrency());
    }
    if (convention instanceof SwapFixedLegConvention) {
      return Collections.singleton(((SwapFixedLegConvention) convention).getCurrency());
    }
    if (convention instanceof SwapIndexConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((SwapIndexConvention) convention).getSwapConvention());
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + ((SwapIndexConvention) convention).getSwapConvention());
      }
      return getCurrencies(underlyingConvention);
    }
    if (convention instanceof VanillaIborLegConvention) {
      final Convention underlyingConvention = _conventionSource.getConvention(((VanillaIborLegConvention) convention).getIborIndexConvention());
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + ((VanillaIborLegConvention) convention).getIborIndexConvention());
      }
      return getCurrencies(underlyingConvention);
    }
View Full Code Here

    }
    final DeliverablePriceQuotedSwapFutureConvention futureConvention =
        _conventionSource.getConvention(DeliverablePriceQuotedSwapFutureConvention.class, swapFuture.getFutureConvention());
    final SwapConvention underlyingSwapConvention = _conventionSource.getConvention(SwapConvention.class, swapFuture.getSwapConvention());
    final Tenor maturityTenor = swapFuture.getUnderlyingTenor();
    final Convention payLegConvention = _conventionSource.getConvention(underlyingSwapConvention.getPayLegConvention());
    if (payLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + underlyingSwapConvention.getPayLegConvention() + " was null");
    }
    final Convention receiveLegConvention = _conventionSource.getConvention(underlyingSwapConvention.getReceiveLegConvention());
    if (receiveLegConvention == null) {
      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();
View Full Code Here

    _valuationTime = valuationTime;
  }

  @Override
  public InstrumentDefinition<?> visitSwapNode(final SwapNode swapNode) {
    final Convention payLegConvention = _conventionSource.getConvention(swapNode.getPayLegConvention());
    if (payLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + swapNode.getPayLegConvention() + " was null");
    }
    final Convention receiveLegConvention = _conventionSource.getConvention(swapNode.getReceiveLegConvention());
    if (receiveLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + swapNode.getPayLegConvention() + " was null");
    }
    final AnnuityDefinition<? extends PaymentDefinition> payLeg;
    final AnnuityDefinition<? extends PaymentDefinition> receiveLeg;
    final boolean isFloatFloat = ((payLegConvention instanceof VanillaIborLegConvention) || (payLegConvention instanceof OISLegConvention) ||
        (payLegConvention instanceof CompoundingIborLegConvention))
        &&  ((receiveLegConvention instanceof VanillaIborLegConvention) || (receiveLegConvention instanceof OISLegConvention) ||
            (receiveLegConvention instanceof CompoundingIborLegConvention));
    if (payLegConvention instanceof SwapFixedLegConvention) {
      payLeg = getFixedLeg((SwapFixedLegConvention) payLegConvention, swapNode, true);
    } else if (payLegConvention instanceof VanillaIborLegConvention) {
      payLeg = getIborLeg((VanillaIborLegConvention) payLegConvention, swapNode, true, false);
    } else if (payLegConvention instanceof OISLegConvention) {
      payLeg = getOISLeg((OISLegConvention) payLegConvention, swapNode, true, false);
    } else if (payLegConvention instanceof CompoundingIborLegConvention) {
      payLeg = getIborCompoundingLeg((CompoundingIborLegConvention) payLegConvention, swapNode, true, false);
    } else {
      throw new OpenGammaRuntimeException("Cannot handle convention type " + payLegConvention.getClass());
    }
    if (receiveLegConvention instanceof SwapFixedLegConvention) {
      receiveLeg = getFixedLeg((SwapFixedLegConvention) receiveLegConvention, swapNode, false);
    } else if (receiveLegConvention instanceof VanillaIborLegConvention) {
      receiveLeg = getIborLeg((VanillaIborLegConvention) receiveLegConvention, swapNode, false, isFloatFloat);
    } else if (receiveLegConvention instanceof OISLegConvention) {
      receiveLeg = getOISLeg((OISLegConvention) receiveLegConvention, swapNode, false, isFloatFloat);
    } else if (receiveLegConvention instanceof CompoundingIborLegConvention) {
      receiveLeg = getIborCompoundingLeg((CompoundingIborLegConvention) receiveLegConvention, swapNode, false, isFloatFloat);
    } else {
      throw new OpenGammaRuntimeException("Cannot handle convention type " + receiveLegConvention.getClass());
    }
    return new SwapDefinition(payLeg, receiveLeg);
  }
View Full Code Here

    return AnnuityCouponFixedDefinition.from(currency, startDate, maturityDate, paymentPeriod, calendar, dayCount, businessDayConvention, eomLeg, 1, rate, isPayer, stub);       
  }

  private AnnuityDefinition<? extends PaymentDefinition> getIborLeg(final VanillaIborLegConvention convention, final SwapNode swapNode, final boolean isPayer,
       final boolean isMarketDataSpread) {
    final Convention underlyingConvention = _conventionSource.getConvention(convention.getIborIndexConvention());
    if (!(underlyingConvention instanceof IborIndexConvention)) {
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + convention.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();
View Full Code Here

    return AnnuityCouponIborDefinition.from(startDate, maturityDate, indexTenor, 1, iborIndex, isPayer, businessDayConvention, eom, dayCount, calendar, stub);
  }

  private AnnuityDefinition<? extends PaymentDefinition> getIborCompoundingLeg(final CompoundingIborLegConvention convention, final SwapNode swapNode, final boolean isPayer,
       final boolean isMarketDataSpread) {
    final Convention underlyingConvention = _conventionSource.getConvention(convention.getIborIndexConvention());
    if (!(underlyingConvention instanceof IborIndexConvention)) {
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + convention.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();
View Full Code Here

    final ExternalId conventionId = fxForward.getFxForwardConvention();
    final Double forward = _marketData.getDataPoint(_dataId);
    if (forward == null) {
      throw new OpenGammaRuntimeException("Could not get market data for " + _dataId);
    }
    final Convention convention = _conventionSource.getConvention(conventionId);
    if (convention == null) {
      throw new OpenGammaRuntimeException("Could not get convention with id " + conventionId);
    }
    if (!(convention instanceof FXForwardAndSwapConvention)) {
      throw new OpenGammaRuntimeException("Need a convention of type " + FXForwardAndSwapConvention.class + ", have " + convention.getClass());
    }
    final FXForwardAndSwapConvention forwardConvention = (FXForwardAndSwapConvention) convention;
    final ExternalId underlyingConventionId = forwardConvention.getSpotConvention();
    final Convention underlyingConvention = _conventionSource.getConvention(underlyingConventionId);
    if (underlyingConvention == null) {
      throw new OpenGammaRuntimeException("Could not get convention with id " + underlyingConventionId);
    }
    if (!(underlyingConvention instanceof FXSpotConvention)) {
      throw new OpenGammaRuntimeException("Need a convention of type " + FXSpotConvention.class + ", have " + convention.getClass());
View Full Code Here

    _valuationTime = valuationTime;
  }

  @Override
  public InstrumentDefinition<?> visitCashNode(final CashNode cashNode) {
    final Convention convention = _conventionSource.getConvention(cashNode.getConvention());
    if (convention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + cashNode.getConvention() + " was null");
    }
    final Double rate = _marketData.getDataPoint(_dataId);
    if (rate == null) {
      throw new OpenGammaRuntimeException("Could not get market data for " + _dataId);
    }
    final Period startPeriod = cashNode.getStartTenor().getPeriod();
    final Period maturityPeriod = cashNode.getMaturityTenor().getPeriod();
    if (convention instanceof DepositConvention) {
      final DepositConvention depositConvention = (DepositConvention) convention;
      final Currency currency = depositConvention.getCurrency();
      final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, depositConvention.getRegionCalendar());
      final BusinessDayConvention businessDayConvention = depositConvention.getBusinessDayConvention();
      final boolean isEOM = depositConvention.isIsEOM();
      final DayCount dayCount = depositConvention.getDayCount();
      final int settlementDays = depositConvention.getSettlementDays();
      final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar);
      final ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spotDate, startPeriod, businessDayConvention, calendar, isEOM);
      final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate, maturityPeriod, businessDayConvention, calendar, isEOM);
      final double accrualFactor = dayCount.getDayCountFraction(startDate, endDate);
      return new CashDefinition(currency, startDate, endDate, 1, rate, accrualFactor);
    } else if (convention instanceof IborIndexConvention) {
      final IborIndexConvention iborConvention = (IborIndexConvention) convention;
      final Currency currency = iborConvention.getCurrency();
      final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, iborConvention.getRegionCalendar());
      final BusinessDayConvention businessDayConvention = iborConvention.getBusinessDayConvention();
      final boolean isEOM = iborConvention.isIsEOM();
      final DayCount dayCount = iborConvention.getDayCount();
      final int settlementDays = iborConvention.getSettlementDays();
      final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar);
      final ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spotDate, startPeriod, businessDayConvention, calendar, isEOM);
      final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate, maturityPeriod, businessDayConvention, calendar, isEOM);
      final double accrualFactor = dayCount.getDayCountFraction(startDate, endDate);
      final int spotLag = iborConvention.getSettlementDays();
      final boolean eom = iborConvention.isIsEOM();
      final long months = maturityPeriod.toTotalMonths() - startPeriod.toTotalMonths();
      final Period indexTenor = Period.ofMonths((int) months);
      final IborIndex iborIndex = new IborIndex(currency, indexTenor, spotLag, dayCount, businessDayConvention, eom, convention.getName());
      return new DepositIborDefinition(currency, startDate, endDate, 1, rate, accrualFactor, iborIndex);
    } else {
      throw new OpenGammaRuntimeException("Could not handle convention of type " + convention.getClass());
    }
  }
View Full Code Here

    if (definition instanceof InstrumentDefinitionWithData<?, ?> && requiresFixingSeries(node.getCurveNode())) {
      if (node.getCurveNode() instanceof ZeroCouponInflationNode) {
        ArgumentChecker.notNull(timeSeries, "time series");

        ExternalId priceIndexId;
        final Convention inflationLegConvention = _conventionSource.getConvention(((ZeroCouponInflationNode) node.getCurveNode()).getInflationLegConvention());
        if (inflationLegConvention instanceof InflationLegConvention) {
          final ExternalId priceIndexConventionId = ((InflationLegConvention) inflationLegConvention).getPriceIndexConvention();
          final Convention priceIndexConvention = _conventionSource.getConvention(priceIndexConventionId);
          if (priceIndexConvention instanceof PriceIndexConvention) {
            priceIndexId = ((PriceIndexConvention) priceIndexConvention).getPriceIndexId();
          } else {
            throw new OpenGammaRuntimeException("Unexpected convention type for price index");
          }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.convention.Convention

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.