@Override public Set<ComputedValue> execute( final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final Object positionOrNode = getTarget(target); final ConventionBundleSource conventionSource = OpenGammaExecutionContext.getConventionBundleSource(executionContext); final ConventionBundle bundle = conventionSource.getConventionBundle( ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, "USD_CAPM")); final Clock snapshotClock = executionContext.getValuationClock(); final LocalDate now = snapshotClock.zonedDateTime().toLocalDate(); final ValueRequirement desiredValue = desiredValues.iterator().next(); final ValueProperties constraints = desiredValue.getConstraints(); final Period samplingPeriod = getSamplingPeriod(constraints.getValues(ValuePropertyNames.SAMPLING_PERIOD)); final LocalDate startDate = now.minus(samplingPeriod); final HistoricalTimeSeries riskFreeRateTSObject = (HistoricalTimeSeries) inputs.getValue(ValueRequirementNames.HISTORICAL_TIME_SERIES); final Object assetPnLObject = inputs.getValue( new ValueRequirement( ValueRequirementNames.PNL_SERIES, positionOrNode)); // TODO replace with return series when portfolio weights are in if (assetPnLObject == null) { throw new OpenGammaRuntimeException("Asset P&L was null"); } final Object assetFairValueObject = inputs.getValue(new ValueRequirement(ValueRequirementNames.FAIR_VALUE, positionOrNode)); if (assetFairValueObject == null) { throw new OpenGammaRuntimeException("Asset fair value was null"); } final Object betaObject = inputs.getValue(new ValueRequirement(ValueRequirementNames.CAPM_BETA, positionOrNode)); if (betaObject == null) { throw new OpenGammaRuntimeException("Beta was null"); } final double beta = (Double) betaObject; final double fairValue = (Double) assetFairValueObject; DoubleTimeSeries<?> assetReturnTS = ((DoubleTimeSeries<?>) assetPnLObject).divide(fairValue); DoubleTimeSeries<?> riskFreeReturnTS = riskFreeRateTSObject.getTimeSeries().divide(100 * DAYS_PER_YEAR); DoubleTimeSeries<?>[] series = TimeSeriesIntersector.intersect(riskFreeReturnTS, assetReturnTS); riskFreeReturnTS = series[0]; assetReturnTS = series[1]; final TreynorRatioCalculator calculator = getCalculator(constraints.getValues(ValuePropertyNames.EXCESS_RETURN_CALCULATOR)); final double ratio = calculator.evaluate(assetReturnTS, riskFreeReturnTS, beta); final ValueProperties resultProperties = getResultProperties(desiredValues.iterator().next()); return Sets.newHashSet( new ComputedValue( new ValueSpecification( new ValueRequirement( ValueRequirementNames.TREYNOR_RATIO, positionOrNode, resultProperties), getUniqueId()), ratio)); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); Set<String> values = constraints.getValues(VALUE_PROPERTY_NAME); final String inputValue; if ((values == null) || values.isEmpty()) { inputValue = DEFAULT_VALUE_NAME; } else if (values.size() == 1) { inputValue = values.iterator().next(); } else { return null; } // Propogate the desired value constraints onto the requirements, removing those specific to // this function and adding a unit homogeneity clause final ValueProperties.Builder requirementConstraintsBuilder = constraints.copy().withoutAny(VALUE_PROPERTY_NAME); for (String unit : UnitProperties.unitPropertyNames()) { values = constraints.getValues(unit); if (values == null) { // Unit was not specified on the output, but we specify it on the inputs so we can check // homogeneity to ensure the division is valid requirementConstraintsBuilder.withOptional(unit); } } // Request value on the value and parent final ValueProperties requirementConstraints = requirementConstraintsBuilder.get(); return ImmutableSet.of( new ValueRequirement(inputValue, getValueTarget(target), requirementConstraints), new ValueRequirement(inputValue, getParentTarget(target), requirementConstraints)); }
@Test public void EmptyProperties() { final MockPropertyPreservingFunction func = getFunction(); final ValueProperties props = ValueProperties.none(); final ValueProperties expected = ValueProperties.none(); assertEqual(expected, func, props); }
protected static ValueRequirement getCurveRequirement( final String curveName, final String forwardCurveName, final String fundingCurveName, final String calculationMethod, final Currency currency) { final ValueProperties.Builder properties; if (calculationMethod.equals(InterpolatedDataProperties.CALCULATION_METHOD_NAME)) { properties = ValueProperties.builder() .with(ValuePropertyNames.CURVE, curveName) .withAny(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME) .withAny(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME) .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, calculationMethod); } else { properties = ValueProperties.builder() .with(ValuePropertyNames.CURVE, curveName) .with(YieldCurveFunction.PROPERTY_FORWARD_CURVE, forwardCurveName) .with(YieldCurveFunction.PROPERTY_FUNDING_CURVE, fundingCurveName) .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, calculationMethod); } return new ValueRequirement( ValueRequirementNames.YIELD_CURVE, ComputationTargetType.PRIMITIVE, currency.getUniqueId(), properties.get()); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> forwardCurveCalculationMethods = constraints.getValues(CURVE_CALCULATION_METHOD); if (forwardCurveCalculationMethods == null || forwardCurveCalculationMethods.size() != 1) { return null; } final Set<String> surfaceNames = constraints.getValues(SURFACE); if (surfaceNames == null || surfaceNames.size() != 1) { return null; } final String surfaceName = surfaceNames.iterator().next(); final ValueRequirement forwardCurveRequirement = getForwardCurveRequirement(target, desiredValue); final ValueRequirement volatilitySurfaceRequirement = getVolatilityDataRequirement( target, surfaceName, getInstrumentType(), getSurfaceQuoteType(), getSurfaceQuoteUnits()); final ValueRequirement interpolatorRequirement = getInterpolatorRequirement(target, desiredValue); return Sets.newHashSet( interpolatorRequirement, forwardCurveRequirement, volatilitySurfaceRequirement); }
@Override public Set<ComputedValue> execute( final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { String curveName = null; String curveCalculationConfig = null; for (final ValueRequirement requirement : desiredValues) { final ValueProperties constraints = requirement.getConstraints(); final Set<String> values = constraints.getValues(ValuePropertyNames.CURVE); if (values != null) { curveName = values.iterator().next(); } final Set<String> curveConfigValues = constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG); if (curveConfigValues != null) { curveCalculationConfig = curveConfigValues.iterator().next(); } } assert curveName != null; assert curveCalculationConfig != null; final RawSecurity security = (RawSecurity) target.getSecurity(); // final BigDecimal qty = target.getPosition().getQuantity(); final ValueRequirement curveRequirement = getCurveRequirement(target, curveName, curveCalculationConfig); final Object curveObject = inputs.getValue(curveRequirement); if (curveObject == null) { throw new OpenGammaRuntimeException("Could not get " + curveRequirement); } Object curveSpecObject = null; final ValueRequirement curveSpecRequirement = getCurveSpecRequirement(target, curveName); curveSpecObject = inputs.getValue(curveSpecRequirement); if (curveSpecObject == null) { throw new OpenGammaRuntimeException("Could not get " + curveSpecRequirement); } final YieldAndDiscountCurve curve = (YieldAndDiscountCurve) curveObject; final InterpolatedYieldCurveSpecificationWithSecurities curveSpec = (InterpolatedYieldCurveSpecificationWithSecurities) curveSpecObject; final LinkedHashMap<String, YieldAndDiscountCurve> interpolatedCurves = new LinkedHashMap<String, YieldAndDiscountCurve>(); interpolatedCurves.put(curveName, curve); final YieldCurveBundle bundle = new YieldCurveBundle(interpolatedCurves); final DoubleMatrix1D sensitivitiesForCurves = getSensitivities(executionContext.getSecuritySource(), inputs, security, curveSpec, curve); final ValueProperties.Builder properties = createValueProperties(target) .with(ValuePropertyNames.CURVE, curveName) .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfig); final ComputationTargetSpecification targetSpec = target.toSpecification(); final ValueSpecification resultSpec = new ValueSpecification(YCNS_REQUIREMENT, targetSpec, properties.get()); final Set<ComputedValue> results = YieldCurveNodeSensitivitiesHelper.getInstrumentLabelledSensitivitiesForCurve( curveName, bundle, sensitivitiesForCurves, curveSpec, resultSpec); // s_logger.debug("execute, returning " + results); return results; }
private void assertEqualOrdered( final ValueProperties expected, final MockPropertyPreservingFunction func, final Collection<ValueSpecification> specses) { final ValueProperties resultProperties = func.getResultProperties(specses); final ValueProperties filteredResult = resultProperties.copy().withoutAny(ValuePropertyNames.FUNCTION).get(); assertEquals(expected, filteredResult); }
@Test public void SingleNonMatchingProperty() { final MockPropertyPreservingFunction func = getFunction(); final List<ValueSpecification> specses = getSpecs( ValueProperties.builder().with("A", "V").get(), ValueProperties.builder().with("A", "X").get()); assertNull(func.getResultProperties(specses)); }
@Test public void SingleMatchingOtherProperty() { final MockPropertyPreservingFunction func = getFunction(); assertEqual( ValueProperties.none(), func, ValueProperties.builder().with("Z", "A").get(), ValueProperties.builder().with("Z", "A").get()); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> surfaceNames = constraints.getValues(ValuePropertyNames.SURFACE); if (surfaceNames == null || surfaceNames.size() != 1) { return null; } final Set<String> curveCalculationConfigNames = constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG); if (curveCalculationConfigNames == null || curveCalculationConfigNames.size() != 1) { return null; } final String curveCalculationConfigName = curveCalculationConfigNames.iterator().next(); final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context); final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource = new ConfigDBCurveCalculationConfigSource(configSource); final MultiCurveCalculationConfig curveCalculationConfig = curveCalculationConfigSource.getConfig(curveCalculationConfigName); if (curveCalculationConfig == null) { s_logger.error( "Could not find curve calculation configuration named " + curveCalculationConfigName); return null; } final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity()); if (!ComputationTargetSpecification.of(currency).equals(curveCalculationConfig.getTarget())) { s_logger.error( "Security currency and curve calculation config id were not equal; have {} and {}", currency, curveCalculationConfig.getTarget()); return null; } final String surfaceName = surfaceNames.iterator().next(); final Set<ValueRequirement> requirements = new HashSet<>(); requirements.addAll( YieldCurveFunctionUtils.getCurveRequirements( curveCalculationConfig, curveCalculationConfigSource)); requirements.add(getVolatilityRequirement(surfaceName, currency)); final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); try { final Set<ValueRequirement> timeSeriesRequirements = _definitionConverter.getConversionTimeSeriesRequirements( security, security.accept(_visitor)); if (timeSeriesRequirements == null) { return null; } requirements.addAll(timeSeriesRequirements); return requirements; } catch (final Exception e) { s_logger.error(e.getMessage()); return null; } }
public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { Set<ValueRequirement> superReqs = super.getRequirements(context, target, desiredValue); if (superReqs == null) { return null; } // Test constraints are provided, else set to "" final ValueProperties constraints = desiredValue.getConstraints(); ValueProperties.Builder scenarioDefaults = null; final Set<String> priceShiftSet = constraints.getValues(s_priceShift); if (priceShiftSet == null || priceShiftSet.isEmpty()) { scenarioDefaults = constraints.copy().withoutAny(s_priceShift).with(s_priceShift, ""); } final Set<String> priceShiftTypeSet = constraints.getValues(s_priceShiftType); if (priceShiftTypeSet == null || priceShiftTypeSet.isEmpty()) { if (scenarioDefaults == null) { scenarioDefaults = constraints .copy() .withoutAny(s_priceShiftType) .with(s_priceShiftType, "Multiplicative"); } else { scenarioDefaults = scenarioDefaults.withoutAny(s_priceShiftType).with(s_priceShiftType, "Multiplicative"); } } final Set<String> volShiftSet = constraints.getValues(s_volShift); if (volShiftSet == null || volShiftSet.isEmpty()) { if (scenarioDefaults == null) { scenarioDefaults = constraints.copy().withoutAny(s_volShift).with(s_volShift, ""); } else { scenarioDefaults = scenarioDefaults.withoutAny(s_volShift).with(s_volShift, ""); } } final Set<String> volShiftSetType = constraints.getValues(s_volShiftType); if (volShiftSetType == null || volShiftSetType.isEmpty()) { if (scenarioDefaults == null) { scenarioDefaults = constraints.copy().withoutAny(s_volShiftType).with(s_volShiftType, "Multiplicative"); } else { scenarioDefaults = scenarioDefaults.withoutAny(s_volShiftType).with(s_volShiftType, "Multiplicative"); } } // If defaults have been added, this adds additional copy of the Function into dep graph with // the adjusted constraints if (scenarioDefaults != null) { return Collections.singleton( new ValueRequirement( getValueRequirementName(), target.toSpecification(), scenarioDefaults.get())); } else { // Scenarios are defined, so we're satisfied return superReqs; } }
@Override public Set<ValueSpecification> getResults( final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { ValueSpecification inputValue = null; ValueSpecification inputParent = null; final UniqueId value = target.getUniqueId(); for (ValueSpecification input : inputs.keySet()) { if (value.equals(input.getTargetSpecification().getUniqueId())) { assert inputValue == null; inputValue = input; } else { assert inputParent == null; inputParent = input; } } final ValueProperties rawResultProperties = inputValue.getProperties().intersect(inputParent.getProperties()); final ValueProperties.Builder resultPropertiesBuilder = rawResultProperties.copy(); for (String unit : UnitProperties.unitPropertyNames()) { final Set<String> valueUnits = inputValue.getProperties().getValues(unit); final Set<String> parentUnits = inputParent.getProperties().getValues(unit); if (valueUnits != null) { if (parentUnits != null) { if (rawResultProperties.getValues(unit) != null) { // The operation is a division, so there are no units on the result resultPropertiesBuilder.withoutAny(unit); } else { // No common intersection between parent and value properties for this unit return null; } } else { // Parent did not include the same units as the value return null; } } else { if (parentUnits != null) { // Value did not include the same units as the parent return null; } } } resultPropertiesBuilder .withoutAny(VALUE_PROPERTY_NAME) .with(VALUE_PROPERTY_NAME, inputValue.getValueName()); resultPropertiesBuilder .withoutAny(ValuePropertyNames.FUNCTION) .with(ValuePropertyNames.FUNCTION, getUniqueId()); return Collections.singleton( new ValueSpecification( ValueRequirementNames.WEIGHT, target.toSpecification(), resultPropertiesBuilder.get())); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> forwardCurveNames = constraints.getValues(YieldCurveFunction.PROPERTY_FORWARD_CURVE); if (forwardCurveNames == null || forwardCurveNames.size() != 1) { return null; } final Set<String> fundingCurveNames = constraints.getValues(YieldCurveFunction.PROPERTY_FUNDING_CURVE); if (fundingCurveNames == null || fundingCurveNames.size() != 1) { return null; } final Set<String> surfaceNames = constraints.getValues(ValuePropertyNames.SURFACE); if (surfaceNames == null || surfaceNames.size() != 1) { return null; } final Set<String> curveCalculationMethods = constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_METHOD); if (curveCalculationMethods == null || curveCalculationMethods.size() != 1) { return null; } final String forwardCurveName = forwardCurveNames.iterator().next(); final String fundingCurveName = fundingCurveNames.iterator().next(); final String surfaceName = surfaceNames.iterator().next(); final String curveCalculationMethod = curveCalculationMethods.iterator().next(); final Set<ValueRequirement> requirements = Sets.newHashSetWithExpectedSize(4); final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity()); requirements.add( getCurveRequirement( forwardCurveName, forwardCurveName, fundingCurveName, curveCalculationMethod, currency)); requirements.add( getCurveRequirement( fundingCurveName, forwardCurveName, fundingCurveName, curveCalculationMethod, currency)); requirements.add(getVolatilityRequirement(surfaceName, currency)); return requirements; }
private ValueSpecification getSpec(final ValueProperties props) { final Builder realProps = props.copy().with(ValuePropertyNames.FUNCTION, "SomeFunc"); final ValueSpecification spec = new ValueSpecification( "X", ComputationTargetSpecification.of(Currency.USD), realProps.get()); return spec; }
@Override public Set<ValueSpecification> getResults( final FunctionCompilationContext context, final ComputationTarget target) { return Collections.singleton( new ValueSpecification( ValueRequirementNames.WEIGHT, target.toSpecification(), ValueProperties.all())); }
@Override public Set<ValueSpecification> getResults( final FunctionCompilationContext context, final ComputationTarget target) { return Sets.newHashSet( new ValueSpecification( ValueRequirementNames.PNL_SERIES, target.toSpecification(), ValueProperties.all())); }
@Override public Set<ValueSpecification> getResults( FunctionCompilationContext context, ComputationTarget target) { return ImmutableSet.of( new ValueSpecification( ValueRequirementNames.TARGET, target.toSpecification(), ValueProperties.all())); }
// Note that createValueProperties is _not_ used - use will mean the engine can't find the // requirement private ValueRequirement getDiscountRequirement(EquityVarianceSwapSecurity security) { ValueProperties properties = ValueProperties.builder().with(ValuePropertyNames.CURVE, _curveDefinitionName).get(); return new ValueRequirement( ValueRequirementNames.YIELD_CURVE, ComputationTargetType.PRIMITIVE, security.getCurrency().getUniqueId(), properties); }
private ValueRequirement getInterpolatorRequirement( final ComputationTarget target, final ValueRequirement desiredValue) { return new ValueRequirement( ValueRequirementNames.BLACK_VOLATILITY_SURFACE_INTERPOLATOR, target.toSpecification(), BlackVolatilitySurfaceUtils.addVolatilityInterpolatorProperties( ValueProperties.builder().get(), desiredValue) .get()); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> payCurveNames = constraints.getValues(ValuePropertyNames.PAY_CURVE); if (payCurveNames == null || payCurveNames.size() != 1) { return null; } final Set<String> receiveCurveNames = constraints.getValues(ValuePropertyNames.RECEIVE_CURVE); if (receiveCurveNames == null || receiveCurveNames.size() != 1) { return null; } final Set<String> payCurveConfigNames = constraints.getValues(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG); if (payCurveConfigNames == null || payCurveConfigNames.size() != 1) { return null; } final Set<String> receiveCurveConfigNames = constraints.getValues(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG); if (receiveCurveConfigNames == null || receiveCurveConfigNames.size() != 1) { return null; } final Set<String> daysForwardNames = constraints.getValues(PROPERTY_DAYS_TO_MOVE_FORWARD); if (daysForwardNames == null || daysForwardNames.size() != 1) { return null; } final String payCurveName = payCurveNames.iterator().next(); final String receiveCurveName = receiveCurveNames.iterator().next(); final String payCurveCalculationConfig = payCurveConfigNames.iterator().next(); final String receiveCurveCalculationConfig = receiveCurveConfigNames.iterator().next(); final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final Currency payCurrency = security.accept(ForexVisitors.getPayCurrencyVisitor()); final Currency receiveCurrency = security.accept(ForexVisitors.getReceiveCurrencyVisitor()); final ValueRequirement payFundingCurve = YieldCurveFunctionUtils.getCurveRequirementForFXForward( ComputationTargetSpecification.of(payCurrency), payCurveName, payCurveCalculationConfig, true); final ValueRequirement receiveFundingCurve = YieldCurveFunctionUtils.getCurveRequirementForFXForward( ComputationTargetSpecification.of(receiveCurrency), receiveCurveName, receiveCurveCalculationConfig, false); final ValueProperties optionalProperties = ValueProperties.builder() .with(PROPERTY_DAYS_TO_MOVE_FORWARD, daysForwardNames) .withOptional(PROPERTY_DAYS_TO_MOVE_FORWARD) .get(); final ValueRequirement pairQuoteRequirement = new ValueRequirement( ValueRequirementNames.CURRENCY_PAIRS, ComputationTargetSpecification.NULL, optionalProperties); return Sets.newHashSet(payFundingCurve, receiveFundingCurve, pairQuoteRequirement); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> curveCalculationConfigNames = constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG); if (curveCalculationConfigNames == null || curveCalculationConfigNames.size() != 1) { return null; } final String curveCalculationConfigName = curveCalculationConfigNames.iterator().next(); final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context); final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource = new ConfigDBCurveCalculationConfigSource(configSource); final MultiCurveCalculationConfig curveCalculationConfig = curveCalculationConfigSource.getConfig(curveCalculationConfigName); if (curveCalculationConfig == null) { s_logger.error( "Could not find curve calculation configuration named " + curveCalculationConfigName); return null; } final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final Currency currency = FinancialSecurityUtils.getCurrency(security); if (!currency.equals(curveCalculationConfig.getUniqueId())) { s_logger.error( "Security currency and curve calculation config id were not equal; have {} and {}", currency, curveCalculationConfig.getUniqueId()); } final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>(); requirements.addAll( YieldCurveFunctionUtils.getCurveRequirements( curveCalculationConfig, curveCalculationConfigSource)); final Set<ValueRequirement> timeSeriesRequirements = getDerivativeTimeSeriesRequirements( security, security.accept(_visitor), _definitionConverter); if (timeSeriesRequirements == null) { return null; } requirements.addAll(timeSeriesRequirements); return requirements; }
protected ValueRequirement getCurveSpecRequirement( final ComputationTarget target, final String curveName) { final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity()); final ValueProperties.Builder properties = ValueProperties.builder().with(ValuePropertyNames.CURVE, curveName); return new ValueRequirement( ValueRequirementNames.YIELD_CURVE_SPEC, ComputationTargetSpecification.of(currency), properties.get()); }
protected ValueRequirement getCurveRequirement( final ComputationTarget target, final String curveName, final String curveCalculationConfig) { final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity()); final ValueProperties.Builder properties = ValueProperties.with(ValuePropertyNames.CURVE, curveName); properties.with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfig); return new ValueRequirement( ValueRequirementNames.YIELD_CURVE, ComputationTargetSpecification.of(currency), properties.get()); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final Set<ValueRequirement> requirements = Sets.newHashSet(); final ValueProperties valueProperties = ValueProperties.builder().withAny(ValuePropertyNames.CURRENCY).get(); requirements.add( new ValueRequirement(CREDIT_REQUIREMENT, target.toSpecification(), valueProperties)); return requirements; }
@Override protected String getFCHTSStart(ValueProperties constraints) { Set<String> startDates = constraints.getValues(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY); if (startDates == null || startDates.size() != 1) { return null; } String startDate = Iterables.getOnlyElement(startDates); Set<String> volWeightingStartDates = constraints.getValues( VolatilityWeightingFunctionUtils.VOLATILITY_WEIGHTING_START_DATE_PROPERTY); if (volWeightingStartDates == null || volWeightingStartDates.size() != 1) { // NOTE jonathan 2013-04-29 -- should start a day earlier so the result after weighting starts // at the startDate, // but need to know previous date with data return startDate; } else { return Iterables.getOnlyElement(volWeightingStartDates); } }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> curveNames = constraints.getValues(CURVE); if (curveNames == null || curveNames.size() != 1) { return null; } final Set<String> curveExposureConfigs = constraints.getValues(CURVE_EXPOSURES); if (curveExposureConfigs == null) { return null; } final Set<String> curveType = constraints.getValues(PROPERTY_CURVE_TYPE); if (curveType == null) { return null; } if (super.getRequirements(context, target, desiredValue) == null) { return null; } final Set<ValueRequirement> requirements = new HashSet<>(); final ValueProperties curveProperties = ValueProperties.with(CURVE, curveNames).get(); final ValueProperties properties = ValueProperties.with(PROPERTY_CURVE_TYPE, curveType) .with(CURVE_EXPOSURES, curveExposureConfigs) .get(); requirements.add( new ValueRequirement( CURVE_DEFINITION, ComputationTargetSpecification.NULL, curveProperties)); requirements.add( new ValueRequirement(BLOCK_CURVE_SENSITIVITIES, target.toSpecification(), properties)); return requirements; }
@Override public Set<ComputedValue> execute( final FunctionExecutionContext context, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) throws AsynchronousExecution { final MultipleCurrencyParameterSensitivity sensitivities = (MultipleCurrencyParameterSensitivity) inputs.getValue(BLOCK_CURVE_SENSITIVITIES); final ValueRequirement desiredValue = desiredValues.iterator().next(); final ValueProperties properties = desiredValue.getConstraints(); final String desiredCurveName = desiredValue.getConstraint(CURVE); final Map<Pair<String, Currency>, DoubleMatrix1D> entries = sensitivities.getSensitivities(); final Set<ComputedValue> results = new HashSet<>(); for (final Map.Entry<Pair<String, Currency>, DoubleMatrix1D> entry : entries.entrySet()) { final String curveName = entry.getKey().getFirst(); if (desiredCurveName.equals(curveName)) { final ValueProperties curveSpecificProperties = properties.copy().withoutAny(CURVE).with(CURVE, curveName).get(); final CurveDefinition curveDefinition = (CurveDefinition) inputs.getValue( new ValueRequirement( CURVE_DEFINITION, ComputationTargetSpecification.NULL, ValueProperties.builder().with(CURVE, curveName).get())); final DoubleLabelledMatrix1D ycns = MultiCurveUtils.getLabelledMatrix(entry.getValue(), curveDefinition); final ValueSpecification spec = new ValueSpecification( YIELD_CURVE_NODE_SENSITIVITIES, target.toSpecification(), curveSpecificProperties); results.add(new ComputedValue(spec, ycns)); return results; } } s_logger.info( "Could not get sensitivities to " + desiredCurveName + " for " + target.getName()); return Collections.emptySet(); }
@Test public void OptionalProperty() { final MockPropertyPreservingFunction func = getFunction(); final ValueProperties p = ValueProperties.builder() .withOptional("C") .withAny("C") .with("D", "X") .withOptional("D") .get(); assertEqual(p, func, p, p); }
protected static ValueRequirement getCurveRequirement( final UniqueIdentifiable id, final String yieldCurveName, final String curveCalculationConfigName, final String curveCalculationMethod) { final ValueProperties properties = ValueProperties.builder() .with(ValuePropertyNames.CURVE, yieldCurveName) .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfigName) .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, curveCalculationMethod) .get(); return new ValueRequirement(ValueRequirementNames.YIELD_CURVE, id.getUniqueId(), properties); }
@Override public Set<ValueRequirement> getRequirements( final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final Set<ValueRequirement> requirements = super.getRequirements(context, target, desiredValue); if (requirements == null) { return null; } final ValueProperties constraints = desiredValue.getConstraints(); final Set<String> cutoffNames = constraints.getValues(SABRRightExtrapolationFunction.PROPERTY_CUTOFF_STRIKE); if (cutoffNames == null || cutoffNames.size() != 1) { return null; } final Set<String> muNames = constraints.getValues(SABRRightExtrapolationFunction.PROPERTY_TAIL_THICKNESS_PARAMETER); if (muNames == null || muNames.size() != 1) { return null; } return requirements; }