@SuppressWarnings("synthetic-access")
 @Override
 public Set<ValueRequirement> getTimeSeriesRequirements(
     final SwapSecurity security, final String[] curveNames) {
   Validate.notNull(security, "security");
   final SwapLeg payLeg = security.getPayLeg();
   final SwapLeg receiveLeg = security.getReceiveLeg();
   final ZonedDateTime swapStartDate = security.getEffectiveDate();
   final ZonedDateTime swapStartLocalDate =
       ZonedDateTime.of(swapStartDate.toLocalDate(), LocalTime.of(0, 0), TimeZone.UTC);
   final ValueRequirement payLegTS =
       getIndexTimeSeriesRequirement(
           InterestRateInstrumentType.getInstrumentTypeFromSecurity(security),
           payLeg,
           swapStartLocalDate);
   final ValueRequirement receiveLegTS =
       getIndexTimeSeriesRequirement(
           InterestRateInstrumentType.getInstrumentTypeFromSecurity(security),
           receiveLeg,
           swapStartLocalDate);
   final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
   if (payLegTS != null) {
     requirements.add(payLegTS);
   }
   if (receiveLegTS != null) {
     requirements.add(receiveLegTS);
   }
   return requirements;
 }
Пример #2
0
 @Override
 public boolean equals(Object obj) {
   if (obj == this) {
     return true;
   }
   if (obj != null && obj.getClass() == this.getClass()) {
     SwapSecurity other = (SwapSecurity) obj;
     return JodaBeanUtils.equal(getTradeDate(), other.getTradeDate())
         && JodaBeanUtils.equal(getEffectiveDate(), other.getEffectiveDate())
         && JodaBeanUtils.equal(getMaturityDate(), other.getMaturityDate())
         && JodaBeanUtils.equal(getCounterparty(), other.getCounterparty())
         && JodaBeanUtils.equal(getPayLeg(), other.getPayLeg())
         && JodaBeanUtils.equal(getReceiveLeg(), other.getReceiveLeg())
         && super.equals(obj);
   }
   return false;
 }
 @Override
 @SuppressWarnings({"unchecked", "synthetic-access"})
 public InstrumentDerivative convert(
     final SwapSecurity security,
     final SwapDefinition definition,
     final ZonedDateTime now,
     final String[] curveNames,
     final HistoricalTimeSeriesBundle timeSeries) {
   Validate.notNull(security, "security");
   final SwapLeg payLeg = security.getPayLeg();
   final SwapLeg receiveLeg = security.getReceiveLeg();
   final ZonedDateTime fixingSeriesStartDate =
       security.getEffectiveDate().isBefore(now) ? security.getEffectiveDate() : now;
   final ZonedDateTime fixingSeriesStartLocalDate =
       ZonedDateTime.of(
           fixingSeriesStartDate.toLocalDate(), LocalTime.of(0, 0), TimeZone.UTC);
   final boolean includeCurrentDatesFixing = true;
   final DoubleTimeSeries<ZonedDateTime> payLegTS =
       getIndexTimeSeries(
           payLeg, fixingSeriesStartLocalDate, now, includeCurrentDatesFixing, timeSeries);
   final DoubleTimeSeries<ZonedDateTime> receiveLegTS =
       getIndexTimeSeries(
           receiveLeg,
           fixingSeriesStartLocalDate,
           now,
           includeCurrentDatesFixing,
           timeSeries);
   if (payLegTS != null) {
     if (receiveLegTS != null) {
       try {
         return definition.toDerivative(
             now, new DoubleTimeSeries[] {payLegTS, receiveLegTS}, curveNames);
       } catch (final OpenGammaRuntimeException e) {
         final ExternalId id =
             ((FloatingInterestRateLeg) payLeg).getFloatingReferenceRateId();
         throw new OpenGammaRuntimeException(
             "Could not get fixing value for series with identifier " + id, e);
       }
     }
     if (InterestRateInstrumentType.getInstrumentTypeFromSecurity(security)
         == InterestRateInstrumentType.SWAP_FIXED_CMS) {
       return definition.toDerivative(
           now, new DoubleTimeSeries[] {payLegTS, payLegTS}, curveNames);
     }
     try {
       return definition.toDerivative(now, new DoubleTimeSeries[] {payLegTS}, curveNames);
     } catch (final OpenGammaRuntimeException e) {
       final ExternalId id = ((FloatingInterestRateLeg) payLeg).getFloatingReferenceRateId();
       throw new OpenGammaRuntimeException(
           "Could not get fixing value for series with identifier " + id, e);
     }
   }
   if (receiveLegTS != null) {
     if (InterestRateInstrumentType.getInstrumentTypeFromSecurity(security)
         == InterestRateInstrumentType.SWAP_FIXED_CMS) {
       try {
         return definition.toDerivative(
             now, new DoubleTimeSeries[] {receiveLegTS, receiveLegTS}, curveNames);
       } catch (final OpenGammaRuntimeException e) {
         final ExternalId id =
             ((FloatingInterestRateLeg) payLeg).getFloatingReferenceRateId();
         throw new OpenGammaRuntimeException(
             "Could not get fixing value for series with identifier " + id, e);
       }
     }
     try {
       return definition.toDerivative(
           now, new DoubleTimeSeries[] {receiveLegTS}, curveNames);
     } catch (final OpenGammaRuntimeException e) {
       final ExternalId id =
           ((FloatingInterestRateLeg) receiveLeg).getFloatingReferenceRateId();
       throw new OpenGammaRuntimeException(
           "Could not get fixing value for series with identifier " + id, e);
     }
   }
   throw new OpenGammaRuntimeException(
       "Could not get fixing series for either the pay or receive leg");
 }
  @Override
  public SwaptionSecurity createSecurity() {
    final int optionLength = getRandom(OPTION_LENGTH);
    ZonedDateTime expiry = ZonedDateTime.now().plusMonths(optionLength);
    final SwapSecurity underlying = createUnderlying(expiry.plusMonths(2), expiry);
    final Currency currency = FinancialSecurityUtils.getCurrency(underlying);
    expiry = nextWorkingDay(expiry, currency);
    final boolean isPayer = getRandom().nextBoolean();
    final boolean isLong = getRandom().nextBoolean();
    final boolean isCashSettled = getRandom().nextBoolean();
    final ZonedDateTime settlementDate = nextWorkingDay(expiry.plusDays(2), currency);
    final Double notional =
        underlying
            .getPayLeg()
            .getNotional()
            .accept(
                new NotionalVisitor<Double>() {

                  @Override
                  public Double visitCommodityNotional(final CommodityNotional notional) {
                    return null;
                  }

                  @Override
                  public Double visitInterestRateNotional(final InterestRateNotional notional) {
                    return notional.getAmount();
                  }

                  @Override
                  public Double visitSecurityNotional(final SecurityNotional notional) {
                    return null;
                  }

                  @Override
                  public Double visitVarianceSwapNotional(final VarianceSwapNotional notional) {
                    return notional.getAmount();
                  }
                });
    if (notional == null) {
      return null;
    }
    Double rate = getRate(underlying.getPayLeg());
    if (rate == null) {
      rate = getRate(underlying.getReceiveLeg());
      if (rate == null) {
        return null;
      }
    }
    final SwaptionSecurity security =
        new SwaptionSecurity(
            isPayer,
            getSecurityPersister().storeSecurity(underlying).iterator().next(),
            isLong,
            new Expiry(expiry),
            isCashSettled,
            currency,
            notional,
            new EuropeanExerciseType(),
            settlementDate);
    security.setName(
        createName(
            currency,
            optionLength,
            (int) MONTHS.between(underlying.getEffectiveDate(), underlying.getMaturityDate()),
            notional,
            rate));
    return security;
  }