Examples of Tenor


Examples of com.opengamma.util.time.Tenor

  @Override
  public ForwardSwapSecurity createSecurity() {
    final Currency ccy = getRandomCurrency();
    final ZonedDateTime now = ZonedDateTime.now();
    final ZonedDateTime tradeDate = previousWorkingDay(now.minusDays(getRandom(getDaysTrading())), ccy);
    final Tenor forward = getRandom(FORWARDS);
    final ZonedDateTime forwardDate = nextWorkingDay(now.plus(forward.getPeriod()), ccy);
    ConventionBundle swapConvention = getConventionBundleSource().getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, ccy.getCode() + "_SWAP"));
    if (swapConvention == null) {
      s_logger.error("Couldn't get swap convention for {}", ccy.getCode());
      return null;
    }
    final Tenor maturity = getRandom(TENORS);
    // get the convention of the identifier of the initial rate
    ConventionBundle liborConvention = getConventionBundleSource().getConventionBundle(swapConvention.getSwapFloatingLegInitialRate());
    if (liborConvention == null) {
      s_logger.error("Couldn't get libor convention for {}", swapConvention.getSwapFloatingLegInitialRate());
      return null;
    }
    // look up the rate timeseries identifier out of the bundle
    final ExternalId tsIdentifier = getTimeSeriesIdentifier(liborConvention);
    // look up the value on our chosen trade date
    final HistoricalTimeSeries initialRateSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, tsIdentifier.toBundle(), null, tradeDate.toLocalDate(),
        true, tradeDate.toLocalDate(), true);
    if (initialRateSeries == null || initialRateSeries.getTimeSeries().isEmpty()) {
      s_logger.error("couldn't get series for {} on {}", tsIdentifier, tradeDate);
      return null;
    }
    Double initialRate = initialRateSeries.getTimeSeries().getEarliestValue();
    // get the identifier for the swap rate for the maturity we're interested in (assuming the fixed rate will be =~ swap rate)
    final ExternalId swapRateForMaturityIdentifier = getSwapRateFor(ccy, tradeDate.toLocalDate(), maturity, forward);
    if (swapRateForMaturityIdentifier == null) {
      s_logger.error("Couldn't get swap rate identifier for {} [{}] from {}", new Object[] {ccy, maturity, tradeDate });
      return null;
    }
    final HistoricalTimeSeries fixedRateSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, swapRateForMaturityIdentifier.toBundle(),
        null, tradeDate.toLocalDate(), true,
        tradeDate.toLocalDate(), true);
    if (fixedRateSeries == null) {
      s_logger.error("can't find time series for {} on {}", swapRateForMaturityIdentifier, tradeDate);
      return null;
    }
    Double fixedRate = (fixedRateSeries.getTimeSeries().getEarliestValue() + getRandom().nextDouble()) / 100d;
    Double notional = (double) getRandom(100000) * 1000;
    ZonedDateTime maturityDate = forwardDate.plus(maturity.getPeriod());
    String counterparty = "CParty";
    SwapLeg fixedLeg = new FixedInterestRateLeg(swapConvention.getSwapFixedLegDayCount(),
        swapConvention.getSwapFixedLegFrequency(),
        swapConvention.getSwapFixedLegRegion(),
        swapConvention.getSwapFixedLegBusinessDayConvention(),
        new InterestRateNotional(ccy, notional),
        false, fixedRate);
    FloatingInterestRateLeg floatingLeg = new FloatingInterestRateLeg(swapConvention.getSwapFloatingLegDayCount(),
        swapConvention.getSwapFloatingLegFrequency(),
        swapConvention.getSwapFloatingLegRegion(),
        swapConvention.getSwapFloatingLegBusinessDayConvention(),
        new InterestRateNotional(ccy, notional),
        false, tsIdentifier,
        FloatingRateType.IBOR);
    floatingLeg.setInitialFloatingRate(initialRate);
    String fixedLegDescription = RATE_FORMATTER.format(fixedRate);
    String floatingLegDescription = swapConvention.getSwapFloatingLegInitialRate().getValue();
    boolean isPayFixed = getRandom().nextBoolean();
    SwapLeg payLeg;
    String payLegDescription;
    SwapLeg receiveLeg;
    String receiveLegDescription;
    if (isPayFixed) {
      payLeg = fixedLeg;
      payLegDescription = fixedLegDescription;
      receiveLeg = floatingLeg;
      receiveLegDescription = floatingLegDescription;
    } else {
      payLeg = floatingLeg;
      payLegDescription = floatingLegDescription;
      receiveLeg = fixedLeg;
      receiveLegDescription = fixedLegDescription;
    }
    final ForwardSwapSecurity swap = new ForwardSwapSecurity(tradeDate, tradeDate, maturityDate, counterparty, payLeg, receiveLeg, forwardDate);
    swap.setName("IR Forward Swap " + ccy + " " + NOTIONAL_FORMATTER.format(notional) + " " + maturity.getPeriod() + " from " + forwardDate.toString(DATE_FORMATTER) + " - " + payLegDescription +
        " / " + receiveLegDescription);
    return swap;
  }
View Full Code Here

Examples of com.opengamma.util.time.Tenor

    }
    throw new OpenGammaRuntimeException("can't find instrument mapper definition for " + tenor);
  }

  private static ExternalId getStaticSecurity(final Map<Tenor, CurveInstrumentProvider> instrumentMappers, final LocalDate curveDate, final FixedIncomeStrip strip) {
    final Tenor tenor = strip.getCurveNodePointTime();
    final Tenor payTenor = strip.getPayTenor();
    final Tenor receiveTenor = strip.getReceiveTenor();
    final IndexType payIndexType = strip.getPayIndexType();
    final IndexType receiveIndexType = strip.getReceiveIndexType();
    final CurveInstrumentProvider mapper = instrumentMappers.get(tenor);
    if (mapper != null) {
      return mapper.getInstrument(curveDate, tenor, payTenor, receiveTenor, payIndexType, receiveIndexType);
View Full Code Here

Examples of com.opengamma.util.time.Tenor

    if (expiryRule == null) {
      s_logger.info("No expiry rule has been setup for " + prefix + ". Using Default of 3rd Friday.");
      expiryRule = EXPIRY_RULES.get("DEFAULT");
    }
    final int nthExpiry = nthOfPeriod.getFirst();
    final Tenor period = nthOfPeriod.getSecond();
    final LocalDate expiry = expiryRule.getExpiry(nthExpiry, surfaceDate, period);
    final String expiryCode = BloombergFutureUtils.getShortExpiryCode(expiry);
    ticker.append(expiryCode);
    ticker.append(strike > useCallAboveStrike() ? "C" : "P");
    ticker.append(" ");
View Full Code Here

Examples of com.opengamma.util.time.Tenor

//      throw new OpenGammaRuntimeException("Could not get market data for " + _dataId);
    }
    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();
    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.util.time.Tenor

    final Collection<FixedIncomeStripWithSecurity> securityStrips = new TreeSet<>();
    final LocalDate curveDate = curveSpecification.getCurveDate();
    for (final FixedIncomeStripWithIdentifier strip : curveSpecification.getStrips()) {
      final ZonedDateTime start = curveDate.atTime(CASH_EXPIRY_TIME).atZone(ZoneOffset.UTC);
      final ZonedDateTime maturity = curveDate.plus(strip.getMaturity().getPeriod()).atTime(CASH_EXPIRY_TIME).atZone(ZoneOffset.UTC);
      final Tenor resolvedTenor = Tenor.of(Period.between(curveDate, maturity.toLocalDate()));
      final CashSecurity security = new CashSecurity(currency, curveSpecification.getRegion(), start, maturity, DAY_COUNT, 0, 0);
      securityStrips.add(new FixedIncomeStripWithSecurity(strip.getStrip(), resolvedTenor, maturity, strip.getSecurity(), security));
    }
    return new InterpolatedYieldCurveSpecificationWithSecurities(curveDate, curveSpecification.getName(), curveSpecification.getCurrency(), curveSpecification.getInterpolator(),
        curveSpecification.interpolateYield(), securityStrips);
View Full Code Here

Examples of com.opengamma.util.time.Tenor

      throw new OpenGammaRuntimeException("Need a convention of type " + FXSpotConvention.class + ", have " + convention.getClass());
    }
    final FXSpotConvention spotConvention = (FXSpotConvention) underlyingConvention;
    final Currency payCurrency = fxForward.getPayCurrency();
    final Currency receiveCurrency = fxForward.getReceiveCurrency();
    final Tenor forwardTenor = fxForward.getMaturityTenor();
    final double payAmount = 1;
    final double receiveAmount = forward;
    final int settlementDays = spotConvention.getSettlementDays();
    final ExternalId settlementRegion = forwardConvention.getSettlementRegion();
    final Calendar settlementCalendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, settlementRegion);
    final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, settlementCalendar);
    final ZonedDateTime exchangeDate = ScheduleCalculator.getAdjustedDate(spotDate, forwardTenor.getPeriod(), forwardConvention.getBusinessDayConvention(), settlementCalendar,
        forwardConvention.isIsEOM());
    return ForexDefinition.fromAmounts(payCurrency, receiveCurrency, exchangeDate, payAmount, -receiveAmount);
  }
View Full Code Here

Examples of com.opengamma.util.time.Tenor

    final Iterator<HistoricalTimeSeries> tsIterator = timeSeriesBundle.iterator(MarketDataRequirementNames.MARKET_VALUE);
    if (tsIterator == null) {
      throw new OpenGammaRuntimeException("No nodal market data time-series available");
    }
    for (int t = 0; t < tenors.length; t++) {
      final Tenor tenor = tenors[t];
      final HistoricalTimeSeries dbNodeTimeSeries = tsIterator.next();
      if (dbNodeTimeSeries == null) {
        throw new OpenGammaRuntimeException("No time-series for strip with tenor " + tenor);
      }
      final LocalDateDoubleTimeSeries nodeTimeSeries = samplingFunction.getSampledTimeSeries(dbNodeTimeSeries.getTimeSeries(), schedule);
View Full Code Here

Examples of com.opengamma.util.time.Tenor

        final Map<Pair<Tenor, Tenor>, Double> atmStrikes = data.getATMStrikes();
        final Map<Pair<Tenor, Tenor>, Double> normalizedATMStrikes = new HashMap<>();
        final Map<Pair<Tenor, Tenor>, Double> normalizedATMVols = new HashMap<>();
        for (final Map.Entry<VolatilityPoint, Double> entry : volatilityPoints.entrySet()) {
          final VolatilityPoint oldPoint = entry.getKey();
          final Tenor swapTenor = oldPoint.getSwapTenor();
          final Tenor swaptionExpiry = oldPoint.getOptionExpiry();
          final double relativeStrike = oldPoint.getRelativeStrike();
          if (atmStrikes.containsKey(Pair.of(swapTenor, swaptionExpiry))) {
            final Pair<Tenor, Tenor> tenorPair = Pair.of(swapTenor, swaptionExpiry);
            final double absoluteStrike = atmStrikes.get(tenorPair) + relativeStrike / 10000;
            final double vol = entry.getValue();
View Full Code Here

Examples of com.opengamma.util.time.Tenor

    }
    if (n != secondVolatilityParameterIds.size()) {
      throw new IllegalStateException("Did not have one second volatility parameter id per tenor");
    }
    for (int i = 0; i < n; i++) {
      final Tenor tenor = Tenor.of(Period.parse((String) tenors.get(i).getValue()));
      final ExternalId firstVolatilityParameterId = deserializer.fieldValueToObject(ExternalId.class, firstVolatilityParameterIds.get(i));
      final ExternalId secondVolatilityParameterId = deserializer.fieldValueToObject(ExternalId.class, secondVolatilityParameterIds.get(i));
      volatilityTermStructure.put(tenor, Pair.of(firstVolatilityParameterId, secondVolatilityParameterId));
    }
    final ExternalId correlationId = deserializer.fieldValueToObject(ExternalId.class, message.getByName(CORRELATION_ID));
View Full Code Here

Examples of com.opengamma.util.time.Tenor

        final String relativeStrike = nextLine[7];
        final String ticker = nextLine[8];

        if (ticker != null) {
          final Currency currency = Currency.of(currencyIso);
          final Tenor swapTenor = Tenor.parse("P" + swapPeriod + swapPeriodUnit);
          final Tenor optionExpiry = Tenor.parse("P" + expiry + expiryUnit);
          double sign;
          if ("PY".equals(payOrReceive)) {
            sign = -1;
          } else if ("RC".equals(payOrReceive)) {
            sign = 1;
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.