@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); }
@Override public Set<ValueRequirement> getTimeSeriesRequirements( final FRASecurity security, final String[] curveNames) { final ExternalId indexId = security.getUnderlyingId(); final ConventionBundle indexConvention = getConventionSource().getConventionBundle(indexId); if (indexConvention == null) { throw new OpenGammaRuntimeException( "No conventions found for floating reference rate " + indexId); } final ExternalIdBundle indexIdBundle = indexConvention.getIdentifiers(); final HistoricalTimeSeriesResolutionResult timeSeries = getTimeSeriesResolver() .resolve( indexIdBundle, null, null, null, MarketDataRequirementNames.MARKET_VALUE, null); if (timeSeries == null) { return null; } return Collections.singleton( HistoricalTimeSeriesFunctionUtils.createHTSRequirement( timeSeries, MarketDataRequirementNames.MARKET_VALUE, DateConstraint.VALUATION_TIME.minus(Period.ofDays(7)).previousWeekDay(), true, DateConstraint.VALUATION_TIME, false)); }
/** * Returns the ExternalIDBundle associated to an ExternalId as stored in the convention source. * * @param indexId The external id. * @return The bundle. */ private ExternalIdBundle getIndexIdBundle(final ExternalId indexId) { final ConventionBundle indexConvention = getConventionSource().getConventionBundle(indexId); if (indexConvention == null) { throw new OpenGammaRuntimeException( "No conventions found for floating reference rate " + indexId); } return indexConvention.getIdentifiers(); }
public static Set<ValueRequirement> buildRequirements( final InterpolatedYieldCurveSpecification specification, final FunctionCompilationContext context) { final Set<ValueRequirement> result = new HashSet<ValueRequirement>(); for (final FixedIncomeStripWithIdentifier strip : specification.getStrips()) { result.add( new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, strip.getSecurity())); } final ConventionBundleSource conventionBundleSource = OpenGammaCompilationContext.getConventionBundleSource(context); final ConventionBundle conventionBundle = conventionBundleSource.getConventionBundle( Identifier.of( InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, specification.getCurrency().getCode() + "_SWAP")); final ConventionBundle referenceRateConvention = conventionBundleSource.getConventionBundle( IdentifierBundle.of(conventionBundle.getSwapFloatingLegInitialRate())); final Identifier initialRefRateId = SecurityUtils.bloombergTickerSecurityId( referenceRateConvention.getIdentifiers().getIdentifier(SecurityUtils.BLOOMBERG_TICKER)); result.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, initialRefRateId)); return Collections.unmodifiableSet(result); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final Object positionOrNode = getTarget(target); final Set<ValueRequirement> result = new HashSet<ValueRequirement>(); final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> samplingPeriodNames = constraints.getValues(ValuePropertyNames.SAMPLING_PERIOD); if (samplingPeriodNames == null || samplingPeriodNames.size() != 1) { return null; } final Set<String> scheduleCalculatorNames = constraints.getValues(ValuePropertyNames.SCHEDULE_CALCULATOR); if (scheduleCalculatorNames == null || scheduleCalculatorNames.size() != 1) { return null; } final Set<String> samplingFunctionNames = constraints.getValues(ValuePropertyNames.SAMPLING_FUNCTION); if (samplingFunctionNames == null || samplingFunctionNames.size() != 1) { return null; } final Set<String> returnCalculatorNames = constraints.getValues(ValuePropertyNames.RETURN_CALCULATOR); if (returnCalculatorNames == null || returnCalculatorNames.size() != 1) { return null; } final Set<String> stdDevCalculatorNames = constraints.getValues(ValuePropertyNames.STD_DEV_CALCULATOR); if (stdDevCalculatorNames == null || stdDevCalculatorNames.size() != 1) { return null; } final Set<String> covarianceCalculatorNames = constraints.getValues(ValuePropertyNames.COVARIANCE_CALCULATOR); if (covarianceCalculatorNames == null || covarianceCalculatorNames.size() != 1) { return null; } final Set<String> varianceCalculatorNames = constraints.getValues(ValuePropertyNames.VARIANCE_CALCULATOR); if (varianceCalculatorNames == null || varianceCalculatorNames.size() != 1) { return null; } final String samplingPeriodName = samplingPeriodNames.iterator().next(); final String scheduleCalculatorName = scheduleCalculatorNames.iterator().next(); final String samplingFunctionName = samplingFunctionNames.iterator().next(); final String returnCalculatorName = returnCalculatorNames.iterator().next(); final ValueProperties pnlSeriesProperties = ValueProperties.builder() .withAny(ValuePropertyNames.CURRENCY) .with(ValuePropertyNames.SAMPLING_PERIOD, samplingPeriodName) .with(ValuePropertyNames.SCHEDULE_CALCULATOR, scheduleCalculatorName) .with(ValuePropertyNames.SAMPLING_FUNCTION, samplingFunctionName) .with(ValuePropertyNames.RETURN_CALCULATOR, returnCalculatorName) .get(); final ValueProperties betaProperties = ValueProperties.builder() .with(ValuePropertyNames.SAMPLING_PERIOD, samplingPeriodName) .with(ValuePropertyNames.SCHEDULE_CALCULATOR, scheduleCalculatorName) .with(ValuePropertyNames.SAMPLING_FUNCTION, samplingFunctionName) .with(ValuePropertyNames.RETURN_CALCULATOR, returnCalculatorName) .with( ValuePropertyNames.COVARIANCE_CALCULATOR, covarianceCalculatorNames.iterator().next()) .with(ValuePropertyNames.VARIANCE_CALCULATOR, varianceCalculatorNames.iterator().next()) .get(); result.add( new ValueRequirement( ValueRequirementNames.PNL_SERIES, positionOrNode, pnlSeriesProperties)); result.add(new ValueRequirement(ValueRequirementNames.FAIR_VALUE, positionOrNode)); result.add( new ValueRequirement(ValueRequirementNames.CAPM_BETA, positionOrNode, betaProperties)); final HistoricalTimeSeriesResolver resolver = OpenGammaCompilationContext.getHistoricalTimeSeriesResolver(context); final ConventionBundleSource conventionSource = OpenGammaCompilationContext.getConventionBundleSource(context); final ConventionBundle bundle = conventionSource.getConventionBundle( ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, "USD_CAPM")); final HistoricalTimeSeriesResolutionResult timeSeries = resolver.resolve( bundle.getCAPMMarket(), null, null, null, MarketDataRequirementNames.MARKET_VALUE, _resolutionKey); if (timeSeries == null) { return null; } result.add( HistoricalTimeSeriesFunctionUtils.createHTSRequirement( timeSeries, MarketDataRequirementNames.MARKET_VALUE, DateConstraint.VALUATION_TIME.minus(samplingPeriodName), true, DateConstraint.VALUATION_TIME, true)); return result; }