@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()));
 }
 @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()));
 }
 private static VolatilitySurfaceKey createKey(ValueSpecification valueSpecification) {
   UniqueId uniqueId = valueSpecification.getTargetSpecification().getUniqueId();
   String surface = valueSpecification.getProperties().getStrictValue(ValuePropertyNames.SURFACE);
   String instrumentType = valueSpecification.getProperties().getStrictValue("InstrumentType");
   String quoteType =
       valueSpecification
           .getProperties()
           .getStrictValue(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_QUOTE_TYPE);
   String quoteUnits =
       valueSpecification
           .getProperties()
           .getStrictValue(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_UNITS);
   return VolatilitySurfaceKey.of(uniqueId, surface, instrumentType, quoteType, quoteUnits);
 }
  @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()));
  }
 protected ValueSpecification getOutputSpec(ValueSpecification inputSpec) {
   ValueProperties outputProperties =
       inputSpec
           .getProperties()
           .copy()
           .withoutAny(ValuePropertyNames.FUNCTION)
           .with(ValuePropertyNames.FUNCTION, getUniqueId())
           .get();
   return new ValueSpecification(
       ValueRequirementNames.TARGET, inputSpec.getTargetSpecification(), outputProperties);
 }
 /**
  * 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()));
   }
 }
Ejemplo n.º 8
0
 @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();
 }
Ejemplo n.º 9
0
 @Override
 public String formatCell(BigDecimal value, ValueSpecification valueSpec) {
   DoubleValueFormatter formatter = getFormatter(valueSpec);
   String formattedNumber = formatter.format(value);
   String formattedValue;
   if (formatter.isCurrencyAmount()) {
     Set<String> currencyValues = valueSpec.getProperties().getValues(ValuePropertyNames.CURRENCY);
     String ccy;
     if (currencyValues == null) {
       formattedValue = formattedNumber;
     } else if (currencyValues.isEmpty()) {
       formattedValue = formattedNumber;
     } else {
       ccy = currencyValues.iterator().next();
       formattedValue = ccy + " " + formattedNumber;
     }
   } else {
     formattedValue = formattedNumber;
   }
   return formattedValue;
 }