@Override public Set<ValueSpecification> getResults( final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { if (inputs.size() == 1) { ValueSpecification input = inputs.keySet().iterator().next(); if (getValueRequirementName().equals(input.getValueName())) { return inputs.keySet(); } } ValueSpecification superSpec = super.getResults(context, target, inputs).iterator().next(); Builder properties = superSpec .getProperties() .copy() .withAny(s_priceShift) .withAny(s_volShift) .withAny(s_priceShiftType) .withAny(s_volShiftType); return Collections.singleton( new ValueSpecification( getValueRequirementName(), target.toSpecification(), properties.get())); }
@Override public DistinctMarketDataSelector findMatchingSelector( ValueSpecification valueSpecification, String calculationConfigurationName, SelectorResolver resolver) { if (_calcConfigNames != null && !_calcConfigNames.contains(calculationConfigurationName)) { return null; } if (!s_compatibleVRNames.contains(valueSpecification.getValueName())) { return null; } VolatilitySurfaceKey key = createKey(valueSpecification); if (!contains(_names, key.getName())) { return null; } if (_nameMatchPattern != null && !_nameMatchPattern.getPattern().matcher(key.getName()).matches()) { return null; } if (_nameLikePattern != null && !_nameLikePattern.getPattern().matcher(key.getName()).matches()) { return null; } if (!contains(_instrumentTypes, key.getInstrumentType())) { return null; } if (!contains(_quoteTypes, key.getQuoteType())) { return null; } if (!contains(_quoteUnits, key.getQuoteUnits())) { return null; } return this; }
@Override public Set<ValueSpecification> getResults( final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { if (inputs.size() == 1) { final ValueSpecification input = Iterables.getOnlyElement(inputs.keySet()); if (ValueRequirementNames.PNL_SERIES.equals(input.getValueName())) { return Collections.singleton(input); } } final FXForwardSecurity security = (FXForwardSecurity) target.getPosition().getSecurity(); final CurrencyPair currencyPair = _currencyPairs.getCurrencyPair(security.getPayCurrency(), security.getReceiveCurrency()); if (currencyPair == null) { return null; } final Currency currencyBase = currencyPair.getBase(); String resultCurrency = null; final ValueProperties.Builder builder = createValueProperties(); for (final Map.Entry<ValueSpecification, ValueRequirement> entry : inputs.entrySet()) { final ValueSpecification inputSpec = entry.getKey(); final ValueRequirement inputReq = entry.getValue(); if (inputReq.getValueName().equals(RETURN_SERIES)) { final Set<String> resultCurrencies = inputReq.getConstraints().getValues(CURRENCY); if (resultCurrencies != null && resultCurrencies.size() == 1) { resultCurrency = inputReq.getConstraint(CURRENCY); } else { resultCurrency = currencyBase.getCode(); } } for (final String propertyName : inputSpec.getProperties().getProperties()) { if (ValuePropertyNames.FUNCTION.equals(propertyName)) { continue; } final Set<String> values = inputSpec.getProperties().getValues(propertyName); if (values == null || values.isEmpty()) { builder.withAny(propertyName); } else { builder.with(propertyName, values); } } } if (resultCurrency == null) { return null; } builder .with(ValuePropertyNames.CURRENCY, resultCurrency) .with( ValuePropertyNames.PROPERTY_PNL_CONTRIBUTIONS, ValueRequirementNames.FX_CURRENCY_EXPOSURE); return ImmutableSet.of( new ValueSpecification( ValueRequirementNames.PNL_SERIES, target.toSpecification(), builder.get())); }
private static DoubleValueFormatter getFormatter(ValueSpecification valueSpec) { if (valueSpec == null) { return s_defaultFormatter; } DoubleValueFormatter valueNameFormatter = s_formatters.get(valueSpec.getValueName()); if (valueNameFormatter != null) { return valueNameFormatter; } else { return s_defaultFormatter; } }
@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())); }
/** * Tests if this requirement can be satisfied by a given value specification. * * <p>A {@link ValueSpecification} can satisfy a requirement if both of the following are true: * * <ul> * <li>it is for the same value on the same computation target * <li>the properties associated with the value satisfy the constraints on the requirement * </ul> * * @param valueSpecification the value specification to test, not null * @return {@code true} if this requirement is satisfied by the specification, {@code false} * otherwise. */ public boolean isSatisfiedBy(final ValueSpecification valueSpecification) { // value names are interned by this and specifications if (getValueName() != valueSpecification.getValueName()) { return false; } if (!getTargetSpecification().equals(getTargetSpecification())) { return false; } if (!getConstraints().isSatisfiedBy(valueSpecification.getProperties())) { return false; } return true; }
/** * Simplifies the type based on the associated {@link ComputationTargetResolver}. * * @param valueSpec the specification to process, not null * @return the possibly simplified specification, not null */ public ValueSpecification simplifyType(final ValueSpecification valueSpec) { final ComputationTargetSpecification oldTargetSpec = valueSpec.getTargetSpecification(); final ComputationTargetSpecification newTargetSpec = ComputationTargetResolverUtils.simplifyType( oldTargetSpec, getCompilationContext().getComputationTargetResolver()); if (newTargetSpec == oldTargetSpec) { return MemoryUtils.instance(valueSpec); } else { return MemoryUtils.instance( new ValueSpecification( valueSpec.getValueName(), newTargetSpec, valueSpec.getProperties())); } }
@Override public String toString() { // carefully select useful fields for toString ToStringStyle style = ToStringStyle.SHORT_PREFIX_STYLE; StringBuffer sb = new StringBuffer(); style.appendStart(sb, this); style.append(sb, "result", getInvocationResult(), null); ValueSpecification spec = getSpecification(); if (spec != null) { style.append(sb, "name", spec.getValueName(), null); ComputationTargetSpecification targetSpec = spec.getTargetSpecification(); style.append(sb, "targetId", targetSpec.getIdentifier(), null); style.append(sb, "targetType", targetSpec.getType(), null); style.append(sb, "properties", spec.getProperties(), null); } style.append(sb, "value", getValue(), null); style.appendEnd(sb, this); return sb.toString(); }
@Override public Set<ValueSpecification> getResults( final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { String currencyPairConfigName = null; String payCurveName = null; String payCurveCalculationConfig = null; String receiveCurveName = null; String receiveCurveCalculationConfig = null; String daysForward = null; for (final Map.Entry<ValueSpecification, ValueRequirement> entry : inputs.entrySet()) { final ValueSpecification specification = entry.getKey(); final ValueRequirement requirement = entry.getValue(); if (specification.getValueName().equals(ValueRequirementNames.CURRENCY_PAIRS)) { currencyPairConfigName = specification.getProperty(CurrencyPairsFunction.CURRENCY_PAIRS_NAME); daysForward = requirement.getConstraint(PROPERTY_DAYS_TO_MOVE_FORWARD); } else if (requirement.getValueName().equals(ValueRequirementNames.YIELD_CURVE)) { final ValueProperties constraints = requirement.getConstraints(); if (constraints.getProperties().contains(ValuePropertyNames.PAY_CURVE)) { payCurveName = Iterables.getOnlyElement(constraints.getValues(ValuePropertyNames.CURVE)); payCurveCalculationConfig = Iterables.getOnlyElement( constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG)); } else if (constraints.getProperties().contains(ValuePropertyNames.RECEIVE_CURVE)) { receiveCurveName = Iterables.getOnlyElement(constraints.getValues(ValuePropertyNames.CURVE)); receiveCurveCalculationConfig = Iterables.getOnlyElement( constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG)); } } } assert currencyPairConfigName != null; final CurrencyPairs baseQuotePairs = OpenGammaCompilationContext.getCurrencyPairsSource(context) .getCurrencyPairs(currencyPairConfigName); final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final Currency payCurrency = security.accept(ForexVisitors.getPayCurrencyVisitor()); final Currency receiveCurrency = security.accept(ForexVisitors.getReceiveCurrencyVisitor()); final CurrencyPair baseQuotePair = baseQuotePairs.getCurrencyPair(payCurrency, receiveCurrency); if (baseQuotePair == null) { s_logger.error( "Could not get base/quote pair for currency pair (" + payCurrency + ", " + receiveCurrency + ")"); return null; } final ValueSpecification resultSpec = new ValueSpecification( getValueRequirementName(), target.toSpecification(), getResultProperties( target, payCurveName, receiveCurveName, payCurveCalculationConfig, receiveCurveCalculationConfig, baseQuotePair, daysForward) .get()); return Collections.singleton(resultSpec); }