Package com.opengamma.id

Examples of com.opengamma.id.ExternalId


    return null;
  }

  @Override
  public Void visitCommodityFutureOptionSecurity(CommodityFutureOptionSecurity security) {
    ExternalId underlyingIdentifier = security.getUnderlyingId();
    if (underlyingIdentifier != null) {
      _underlyings.add(ExternalIdBundle.of(underlyingIdentifier));
    }
    return null;
  }
View Full Code Here


    return null;
  }

  @Override
  public Void visitFxFutureOptionSecurity(FxFutureOptionSecurity security) {
    ExternalId underlyingIdentifier = security.getUnderlyingId();
    if (underlyingIdentifier != null) {
      _underlyings.add(ExternalIdBundle.of(underlyingIdentifier));
    }
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitBondFutureOptionSecurity(BondFutureOptionSecurity security) {
    ExternalId underlyingIdentifier = security.getUnderlyingId();
    if (underlyingIdentifier != null) {
      _underlyings.add(ExternalIdBundle.of(underlyingIdentifier));
    }
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitFederalFundsFutureSecurity(FederalFundsFutureSecurity security) {
    ExternalId identifier = security.getUnderlyingId();
    if (identifier != null) {
      _underlyings.add(ExternalIdBundle.of(identifier));
    }
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitCreditDefaultSwapIndexSecurity(CreditDefaultSwapIndexSecurity security) {
    ExternalId identifier = security.getReferenceEntity();
    if (identifier != null) {
      _underlyings.add(ExternalIdBundle.of(identifier));
    }
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitCreditDefaultSwapOptionSecurity(CreditDefaultSwapOptionSecurity security) {
    ExternalId identifier = security.getUnderlyingId();
    if (identifier != null) {
      _underlyings.add(ExternalIdBundle.of(identifier));
    }
    return null;
  }
View Full Code Here

    s_logger.info(sb.toString());
    return securities;
  }

  private Pair<SwaptionSecurity, SwapSecurity> makeSwaptionAndUnderlying(final Random random, final Currency ccy, final LocalDate tradeDate, final Tenor expiry, final Tenor maturity) {
    final ExternalId region = REGIONS.get(ccy);
    final ExternalId floatingRate = IBOR.get(ccy);
    final String swaptionString;
    final Period expiryPeriod = expiry.getPeriod();
    if (expiryPeriod.getYears() != 0) {
      swaptionString = expiryPeriod.getYears() + "Y";
    } else if (expiryPeriod.getMonths() != 0) {
      swaptionString = expiryPeriod.getMonths() + "M";
    } else {
      throw new OpenGammaRuntimeException("Could not handle swaption expiry " + expiry);
    }
    final String swapString;
    final Period maturityPeriod = maturity.getPeriod();
    if (maturityPeriod.getYears() != 0) {
      swapString = maturityPeriod.getYears() + "Y";
    } else if (maturityPeriod.getMonths() != 0) {
      swapString = maturityPeriod.getMonths() + "M";
    } else {
      throw new OpenGammaRuntimeException("Could not handle swap maturity " + maturity);
    }
    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();
    final boolean isCashSettled = random.nextBoolean();
    final boolean payer;
    if (random.nextBoolean()) {
      payLeg = fixedLeg;
      receiveLeg = floatLeg;
      swapName = swapString + " pay " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
      swaptionName = (isLong ? "Long " : "Short ") + swaptionString + " x " + swapString + " pay " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
      payer = true;
    } else {
      payLeg = floatLeg;
      receiveLeg = fixedLeg;
      swapName = swapString + " receive " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
      swaptionName = (isLong ? "Long " : "Short ") + swaptionString + " x " + swapString + " receive " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
      payer = false;
    }
    final SwapSecurity swap = new SwapSecurity(swaptionExpiry, swaptionExpiry.plusDays(2), swapMaturity, COUNTERPARTY, payLeg, receiveLeg);
    swap.setName(swapName);
    final ExternalId underlyingId = ExternalId.of(ID_SCHEME, GUIDGenerator.generate().toString());
    swap.addExternalId(underlyingId);
    final SwaptionSecurity swaption = new SwaptionSecurity(payer, underlyingId, isLong, new Expiry(swaptionExpiry), isCashSettled, ccy);
    swaption.setName(swaptionName);
    swaption.addExternalId(ExternalId.of(ID_SCHEME, GUIDGenerator.generate().toString()));
    return Pair.of(swaption, swap);
View Full Code Here

  }

  private Double getSwapRate(final Currency ccy, final LocalDate tradeDate, final Tenor maturity) {
    final HistoricalTimeSeriesSource historicalSource = getToolContext().getHistoricalTimeSeriesSource();
    final MasterConfigSource configSource = new MasterConfigSource(getToolContext().getConfigMaster());
    final ExternalId swapRateForMaturityIdentifier = getSwapRateFor(configSource, ccy, tradeDate, maturity);
    if (swapRateForMaturityIdentifier == null) {
      throw new OpenGammaRuntimeException("Couldn't get swap rate identifier for " + ccy + " [" + maturity + "]" + " from " + tradeDate);
    }

    final HistoricalTimeSeries fixedRateSeries = historicalSource.getHistoricalTimeSeries("PX_LAST",
        swapRateForMaturityIdentifier.toBundle(), HistoricalTimeSeriesRatingFieldNames.DEFAULT_CONFIG_NAME, tradeDate.minusDays(30), true, tradeDate, true);
    if (fixedRateSeries == null) {
      throw new OpenGammaRuntimeException("Time series for " + swapRateForMaturityIdentifier + " was null");
    }
    if (fixedRateSeries.getTimeSeries().isEmpty()) {
      throw new OpenGammaRuntimeException("Time series for " + swapRateForMaturityIdentifier + " was empty");
View Full Code Here

  private static ExternalId getSwapRateFor(final ConfigSource configSource, final Currency ccy, final LocalDate tradeDate, final Tenor tenor) {
    final CurveSpecificationBuilderConfiguration curveSpecConfig = configSource.getSingle(CurveSpecificationBuilderConfiguration.class, "DEFAULT_" + ccy.getCode(), VersionCorrection.LATEST);
    if (curveSpecConfig == null) {
      throw new OpenGammaRuntimeException("No curve spec builder configuration for DEFAULT_" + ccy.getCode());
    }
    ExternalId swapSecurity;
    if (ccy.equals(Currency.USD)) {
      // Standard (i.e. matches convention) floating leg tenor for USD is 3M
      swapSecurity = curveSpecConfig.getSwap3MSecurity(tradeDate, tenor);
    } else {
      // Standard (i.e. matches convention) floating leg tenor for CHF, JPY, GBP, EUR is 6M
View Full Code Here

  }

  @Override
  public CashSecurity createSecurity() {
    final Currency currency = getRandomCurrency();
    final ExternalId region = ExternalSchemes.currencyRegionId(currency);
    final ZonedDateTime start = previousWorkingDay(ZonedDateTime.now().minusDays(getRandom(60) + 7), currency);
    final int length = getRandom(6) + 3;
    final ZonedDateTime maturity = nextWorkingDay(start.plusMonths(length), currency);
    final ConventionBundle convention = getConventionBundleSource().getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, currency.getCode() + "_GENERIC_CASH"));
    if (convention == null) {
      return null;
    }
    final DayCount dayCount = convention.getDayCount();
    final ExternalId cashRate = getCashRate(currency, start.toLocalDate(), Tenor.ofMonths(length));
    if (cashRate == null) {
      return null;
    }
    final HistoricalTimeSeries timeSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, cashRate.toBundle(), null, start.toLocalDate(), true,
        start.toLocalDate(), true);
    if ((timeSeries == null) || timeSeries.getTimeSeries().isEmpty()) {
      return null;
    }
    final double rate = timeSeries.getTimeSeries().getEarliestValue() * getRandom(0.8, 1.2);
View Full Code Here

TOP

Related Classes of com.opengamma.id.ExternalId

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.