@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; }
@SuppressWarnings("synthetic-access") @Override public InstrumentDerivative convert( final FRASecurity security, final ForwardRateAgreementDefinition definition, final ZonedDateTime now, final String[] curveNames, final HistoricalTimeSeriesBundle timeSeries) { final ExternalId indexId = security.getUnderlyingId(); final ConventionBundle indexConvention = _conventionSource.getConventionBundle(indexId); if (indexConvention == null) { throw new OpenGammaRuntimeException( "No conventions found for floating reference rate " + indexId); } final ExternalIdBundle indexIdBundle = indexConvention.getIdentifiers(); final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, indexIdBundle); if (ts == null) { throw new OpenGammaRuntimeException( "Could not get price time series for " + indexIdBundle); } FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries(); // TODO this normalization should not be done here localDateTS = localDateTS.divide(100); final FastLongDoubleTimeSeries convertedTS = localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS); final LocalTime fixingTime = LocalTime.of(0, 0); final DoubleTimeSeries<ZonedDateTime> indexTS = new ArrayZonedDateTimeDoubleTimeSeries( new ZonedDateTimeEpochMillisConverter(now.getZone(), fixingTime), convertedTS); // TODO: remove the zone return definition.toDerivative(now, indexTS, curveNames); }
private DoubleTimeSeries<ZonedDateTime> getIndexTimeSeries( final SwapLeg leg, final ZonedDateTime swapEffectiveDate, final ZonedDateTime now, final boolean includeEndDate, final HistoricalTimeSeriesBundle timeSeries) { if (leg instanceof FloatingInterestRateLeg) { final FloatingInterestRateLeg floatingLeg = (FloatingInterestRateLeg) leg; final ExternalIdBundle id = getIndexIdForSwap(floatingLeg); // Implementation note: To catch first fixing. SwapSecurity does not have this date. if (now.isBefore(swapEffectiveDate)) { // TODO: review if this is the correct condition return ArrayZonedDateTimeDoubleTimeSeries.EMPTY_SERIES; } final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, id); if (ts == null) { throw new OpenGammaRuntimeException( "Could not get time series of underlying index " + id.getExternalIds().toString() + " bundle used was " + id); } if (ts.getTimeSeries().isEmpty()) { return ArrayZonedDateTimeDoubleTimeSeries.EMPTY_SERIES; } final FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries(); final FastLongDoubleTimeSeries convertedTS = localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS); final LocalTime fixingTime = LocalTime.of( 0, 0); // FIXME CASE Converting a daily historical time series to an arbitrary time. Bad // idea return new ArrayZonedDateTimeDoubleTimeSeries( new ZonedDateTimeEpochMillisConverter(now.getZone(), fixingTime), convertedTS); } return null; }
/** * Returns the time series to be used in the toDerivative method. * * @param id The ExternalId bundle. * @param startDate The time series start date (included in the time series). * @param timeZone The time zone to use for the returned series * @param dataSource The time series data source. * @return The time series. */ private DoubleTimeSeries<ZonedDateTime> getIndexTimeSeries( final ExternalIdBundle id, final TimeZone timeZone, final HistoricalTimeSeriesBundle timeSeries) { final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, id); // Implementation note: the normalization take place in the getHistoricalTimeSeries if (ts == null) { throw new OpenGammaRuntimeException( "Could not get time series of underlying index " + id.getExternalIds().toString()); } if (ts.getTimeSeries().isEmpty()) { return ArrayZonedDateTimeDoubleTimeSeries.EMPTY_SERIES; } final FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries(); final FastLongDoubleTimeSeries convertedTS = localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS); final LocalTime fixingTime = LocalTime.of( 0, 0); // FIXME CASE Converting a daily historical time series to an arbitrary time. Bad // idea return new ArrayZonedDateTimeDoubleTimeSeries( new ZonedDateTimeEpochMillisConverter(timeZone, fixingTime), convertedTS); }
@Override public InstrumentDerivative convert( final CapFloorSecurity security, final AnnuityCapFloorIborDefinition definition, final ZonedDateTime now, final String[] curveNames, final HistoricalTimeSeriesBundle timeSeries) { final ExternalId id = security.getUnderlyingId(); final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, security.getUnderlyingId()); if (ts == null) { throw new OpenGammaRuntimeException("Could not get price time series for " + id); } FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries(); // TODO this normalization should not be done here localDateTS = localDateTS.divide(100); final FastLongDoubleTimeSeries convertedTS = localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS); final LocalTime fixingTime = LocalTime.of(11, 0); final DoubleTimeSeries<ZonedDateTime> indexTS = new ArrayZonedDateTimeDoubleTimeSeries( new ZonedDateTimeEpochMillisConverter(now.getZone(), fixingTime), convertedTS); return definition.toDerivative(now, indexTS, curveNames); }
/** * Adjusts a time to have the the minute-of-hour represented by this object, returning a new time. * * <p>Only the minute-of-hour field is adjusted in the result. The other time fields are * unaffected. * * <p>This instance is immutable and unaffected by this method call. * * @param time the time to be adjusted, not null * @return the adjusted time, never null */ public LocalTime adjustTime(LocalTime time) { return time.withMinuteOfHour(minuteOfHour); }
@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"); }