@Override public Collection<IborIndex> visitSwapDefinition(final SwapDefinition definition) { final Collection<IborIndex> indices = new HashSet<>(); indices.addAll(definition.getFirstLeg().accept(this)); indices.addAll(definition.getSecondLeg().accept(this)); return indices; }
@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"); }