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());
 }
 @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> 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);
 }
 // 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());
 }
 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());
 }
  @Override
  public Set<ValueRequirement> getRequirements(
      final FunctionCompilationContext context,
      final ComputationTarget target,
      final ValueRequirement desiredValue) {
    final Set<ValueRequirement> requirements = new HashSet<>();
    final ValueProperties constraints = desiredValue.getConstraints();

    // curve
    final String curveName = constraints.getStrictValue(ValuePropertyNames.CURVE);
    if (curveName == null) {
      return null;
    }

    // interpolator
    final String interpolatorName =
        constraints.getStrictValue(
            ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_INTERPOLATOR);
    if (interpolatorName == null) {
      return null;
    }

    // interpolator left extrapolator
    final String leftExtrapolatorName =
        constraints.getStrictValue(
            ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_LEFT_EXTRAPOLATOR);
    if (leftExtrapolatorName == null) {
      return null;
    }

    // interpolator right extrapolator
    final String rightExtrapolatorName =
        constraints.getStrictValue(
            ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_RIGHT_EXTRAPOLATOR);
    if (rightExtrapolatorName == null) {
      return null;
    }

    final ValueProperties futureCurveProperties =
        ValueProperties.builder()
            .with(
                InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE,
                InstrumentTypeProperties.EQUITY_FUTURE_PRICE)
            .with(ValuePropertyNames.CURVE, curveName)
            .get();

    requirements.add(
        new ValueRequirement(
            ValueRequirementNames.FUTURE_PRICE_CURVE_DATA,
            target.toSpecification(),
            futureCurveProperties));
    return requirements;
  }
Esempio n. 9
0
 @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;
 }
  @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);
 }
 private static ValueRequirement getVolatilityRequirement(
     final String surface, final Currency currency) {
   final ValueProperties properties =
       ValueProperties.builder()
           .with(ValuePropertyNames.SURFACE, surface)
           .with(
               InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE,
               InstrumentTypeProperties.SWAPTION_ATM)
           .get();
   return new ValueRequirement(
       ValueRequirementNames.INTERPOLATED_VOLATILITY_SURFACE,
       ComputationTargetSpecification.of(Currency.USD),
       properties);
 }
 // Note that createValueProperties is _not_ used - use will mean the engine can't find the
 // requirement
 private ValueRequirement getDiscountRequirement(
     final EquityVarianceSwapSecurity security,
     final String curveName,
     final String curveCalculationConfigName) {
   final ValueProperties properties =
       ValueProperties.builder()
           .with(ValuePropertyNames.CURVE, curveName)
           .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfigName)
           .get();
   return new ValueRequirement(
       ValueRequirementNames.YIELD_CURVE,
       ComputationTargetType.PRIMITIVE,
       security.getCurrency().getUniqueId(),
       properties);
 }
 private static YieldAndDiscountCurve getCurve(
     final FunctionInputs inputs, final Currency currency, final String curveName) {
   final ValueProperties.Builder properties =
       ValueProperties.builder().with(ValuePropertyNames.CURVE, curveName);
   final Object curveObject =
       inputs.getValue(
           new ValueRequirement(
               ValueRequirementNames.YIELD_CURVE,
               ComputationTargetType.PRIMITIVE,
               currency.getUniqueId(),
               properties.get()));
   if (curveObject == null) {
     throw new OpenGammaRuntimeException("Could not get " + curveName + " curve");
   }
   final YieldAndDiscountCurve curve = (YieldAndDiscountCurve) curveObject;
   return curve;
 }
 protected ValueRequirement getVolatilityDataRequirement(
     final ComputationTarget target,
     final String surfaceName,
     final String instrumentType,
     final String surfaceQuoteType,
     final String surfaceQuoteUnits) {
   final ValueRequirement volDataRequirement =
       new ValueRequirement(
           ValueRequirementNames.VOLATILITY_SURFACE_DATA,
           target.toSpecification(),
           ValueProperties.builder()
               .with(SURFACE, surfaceName)
               .with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, instrumentType)
               .with(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_QUOTE_TYPE, surfaceQuoteType)
               .with(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_UNITS, surfaceQuoteUnits)
               .get());
   return volDataRequirement;
 }
 @Override
 public Set<ValueRequirement> getRequirements(
     final FunctionCompilationContext compilationContext,
     final ComputationTarget target,
     final ValueRequirement desiredValue) {
   final ValueProperties constraints = desiredValue.getConstraints();
   final Set<String> rootFinderAbsoluteTolerance =
       constraints.getValues(PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE);
   if (rootFinderAbsoluteTolerance == null || rootFinderAbsoluteTolerance.size() != 1) {
     return null;
   }
   final Set<String> rootFinderRelativeTolerance =
       constraints.getValues(PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE);
   if (rootFinderRelativeTolerance == null || rootFinderRelativeTolerance.size() != 1) {
     return null;
   }
   final Set<String> maxIterations = constraints.getValues(PROPERTY_ROOT_FINDER_MAX_ITERATIONS);
   if (maxIterations == null || maxIterations.size() != 1) {
     return null;
   }
   final Set<String> decomposition = constraints.getValues(PROPERTY_DECOMPOSITION);
   if (decomposition == null || decomposition.size() != 1) {
     return null;
   }
   final Set<String> useFiniteDifference = constraints.getValues(PROPERTY_USE_FINITE_DIFFERENCE);
   if (useFiniteDifference == null || useFiniteDifference.size() != 1) {
     return null;
   }
   if (!_originalConfiguration.getTarget().equals(target.toSpecification())) {
     s_logger.info(
         "Invalid target, was {} - expected {}", target, _originalConfiguration.getTarget());
     return null;
   }
   final ValueProperties properties =
       ValueProperties.builder()
           .with(CURVE_CALCULATION_METHOD, _originalConfiguration.getCalculationMethod())
           .with(CURVE_CALCULATION_CONFIG, _originalConfiguration.getCalculationConfigName())
           .with(CURVE, _originalCurveName)
           .get();
   return Collections.singleton(
       new ValueRequirement(YIELD_CURVE, target.toSpecification(), properties));
 }
 @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();
 }
 @Override
 public void init(final FunctionCompilationContext context) {
   _definition =
       ConfigDBVolatilitySurfaceDefinitionSource.init(context, this)
           .getDefinition(_definitionName, _instrumentType);
   if (_definition == null) {
     throw new OpenGammaRuntimeException(
         "Couldn't find Volatility Surface Definition for "
             + _instrumentType
             + " called "
             + _definitionName);
   }
   final ValueProperties surfaceProperties =
       ValueProperties.builder()
           .with(ValuePropertyNames.SURFACE, _definitionName)
           .with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, _instrumentType)
           .withAny(
               EquityVarianceSwapStaticReplicationFunction
                   .STRIKE_PARAMETERIZATION_METHOD /*, VarianceSwapStaticReplication.StrikeParameterization.STRIKE.toString()*/)
           .get();
   final ComputationTargetSpecification targetSpec =
       ComputationTargetSpecification.of(_definition.getTarget().getUniqueId());
   _requirement =
       new ValueRequirement(
           ValueRequirementNames.STANDARD_VOLATILITY_SURFACE_DATA, targetSpec, surfaceProperties);
   _result =
       new ValueSpecification(
           ValueRequirementNames.INTERPOLATED_VOLATILITY_SURFACE,
           targetSpec,
           createValueProperties()
               .with(ValuePropertyNames.SURFACE, _definitionName)
               .with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, _instrumentType)
               .withAny(
                   EquityVarianceSwapStaticReplicationFunction
                       .STRIKE_PARAMETERIZATION_METHOD /*, VarianceSwapStaticReplication.StrikeParameterization.STRIKE.toString()*/)
               .get());
   _results = Collections.singleton(_result);
 }
 protected static ValueRequirement getSurfaceRequirement(
     final String surfaceName,
     final Currency putCurrency,
     final Currency callCurrency,
     final String interpolatorName,
     final String leftExtrapolatorName,
     final String rightExtrapolatorName) {
   final ValueProperties surfaceProperties =
       ValueProperties.builder()
           .with(ValuePropertyNames.SURFACE, surfaceName)
           .with(
               InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE,
               InstrumentTypeProperties.FOREX)
           .with(InterpolatedDataProperties.X_INTERPOLATOR_NAME, interpolatorName)
           .with(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME, leftExtrapolatorName)
           .with(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME, rightExtrapolatorName)
           .get();
   final UnorderedCurrencyPair currenciesTarget =
       UnorderedCurrencyPair.of(putCurrency, callCurrency);
   return new ValueRequirement(
       ValueRequirementNames.STANDARD_VOLATILITY_SURFACE_DATA,
       currenciesTarget,
       surfaceProperties);
 }
 @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> payCurveCalculationConfigs =
       constraints.getValues(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG);
   if (payCurveCalculationConfigs == null || payCurveCalculationConfigs.size() != 1) {
     return null;
   }
   final Set<String> receiveCurveNames = constraints.getValues(ValuePropertyNames.RECEIVE_CURVE);
   if (receiveCurveNames == null || receiveCurveNames.size() != 1) {
     return null;
   }
   final Set<String> receiveCurveCalculationConfigs =
       constraints.getValues(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG);
   if (receiveCurveCalculationConfigs == null || receiveCurveCalculationConfigs.size() != 1) {
     return null;
   }
   final Set<String> calculationMethods =
       constraints.getValues(ValuePropertyNames.CALCULATION_METHOD);
   if (calculationMethods == null || calculationMethods.size() != 1) {
     final ValueProperties newConstraints =
         constraints
             .copy()
             .withoutAny(ValuePropertyNames.CALCULATION_METHOD)
             .with(
                 ValuePropertyNames.CALCULATION_METHOD,
                 CalculationPropertyNamesAndValues.DISCOUNTING)
             .get();
     return Collections.singleton(
         new ValueRequirement(
             ValueRequirementNames.PNL_SERIES, target.toSpecification(), newConstraints));
   }
   final Set<ValueRequirement> requirements = new HashSet<>();
   final String calculationMethod = Iterables.getOnlyElement(calculationMethods);
   final FinancialSecurity security = (FinancialSecurity) target.getPosition().getSecurity();
   if (CalculationPropertyNamesAndValues.DISCOUNTING.equals(calculationMethod)) {
     requirements.add(
         new ValueRequirement(
             ValueRequirementNames.FX_CURRENCY_EXPOSURE,
             ComputationTargetSpecification.of(target.getPosition().getSecurity()),
             ValueProperties.builder()
                 .with(
                     ValuePropertyNames.CALCULATION_METHOD,
                     CalculationPropertyNamesAndValues.DISCOUNTING)
                 .with(ValuePropertyNames.PAY_CURVE, payCurveNames.iterator().next())
                 .with(
                     ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG,
                     payCurveCalculationConfigs.iterator().next())
                 .with(ValuePropertyNames.RECEIVE_CURVE, receiveCurveNames.iterator().next())
                 .with(
                     ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG,
                     receiveCurveCalculationConfigs.iterator().next())
                 .get()));
   } else if (CalculationPropertyNamesAndValues.FORWARD_POINTS.equals(calculationMethod)) {
     final Set<String> forwardCurveNames =
         constraints.getValues(ValuePropertyNames.FORWARD_CURVE_NAME);
     if (forwardCurveNames == null || forwardCurveNames.size() != 1) {
       return null;
     }
     final String forwardCurveName = Iterables.getOnlyElement(forwardCurveNames);
     requirements.add(
         new ValueRequirement(
             ValueRequirementNames.FX_CURRENCY_EXPOSURE,
             ComputationTargetSpecification.of(target.getPosition().getSecurity()),
             ValueProperties.builder()
                 .with(
                     ValuePropertyNames.CALCULATION_METHOD,
                     CalculationPropertyNamesAndValues.FORWARD_POINTS)
                 .with(ValuePropertyNames.PAY_CURVE, payCurveNames.iterator().next())
                 .with(
                     ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG,
                     payCurveCalculationConfigs.iterator().next())
                 .with(ValuePropertyNames.RECEIVE_CURVE, receiveCurveNames.iterator().next())
                 .with(
                     ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG,
                     receiveCurveCalculationConfigs.iterator().next())
                 .with(ValuePropertyNames.FORWARD_CURVE_NAME, forwardCurveName)
                 .get()));
   } else {
     return null;
   }
   final Set<String> resultCurrencies = constraints.getValues(CURRENCY);
   final Currency payCurrency = security.accept(ForexVisitors.getPayCurrencyVisitor());
   final Currency receiveCurrency = security.accept(ForexVisitors.getReceiveCurrencyVisitor());
   final String resultCurrency;
   final CurrencyPair baseQuotePair =
       _currencyPairs.getCurrencyPair(payCurrency, receiveCurrency);
   final Currency baseCurrency = baseQuotePair.getBase();
   final Currency nonBaseCurrency = baseQuotePair.getCounter();
   if (resultCurrencies != null && resultCurrencies.size() == 1) {
     final Currency ccy = Currency.of(Iterables.getOnlyElement(resultCurrencies));
     if (!(ccy.equals(payCurrency) || ccy.equals(receiveCurrency))) {
       requirements.add(
           ConventionBasedFXRateFunction.getHistoricalTimeSeriesRequirement(
               UnorderedCurrencyPair.of(baseCurrency, ccy)));
       resultCurrency = ccy.getCode();
     } else if (ccy.equals(nonBaseCurrency)) {
       requirements.add(
           ConventionBasedFXRateFunction.getHistoricalTimeSeriesRequirement(
               UnorderedCurrencyPair.of(nonBaseCurrency, baseCurrency)));
       resultCurrency = nonBaseCurrency.getCode();
     } else {
       requirements.add(
           ConventionBasedFXRateFunction.getHistoricalTimeSeriesRequirement(
               UnorderedCurrencyPair.of(baseCurrency, nonBaseCurrency)));
       resultCurrency = baseCurrency.getCode();
     }
   } else {
     resultCurrency = baseCurrency.getCode();
   }
   final ValueProperties fxSpotConstraints =
       desiredValue
           .getConstraints()
           .copy()
           .withoutAny(ValuePropertyNames.PAY_CURVE)
           .withoutAny(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG)
           .withoutAny(ValuePropertyNames.RECEIVE_CURVE)
           .withoutAny(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG)
           .withoutAny(ValuePropertyNames.PROPERTY_PNL_CONTRIBUTIONS)
           .withoutAny(ValuePropertyNames.CURVE_CURRENCY)
           .withoutAny(ValuePropertyNames.CALCULATION_METHOD)
           .withoutAny(ValuePropertyNames.FORWARD_CURVE_NAME)
           .with(CURRENCY, resultCurrency)
           .withOptional(CURRENCY)
           .get();
   final ComputationTargetSpecification fxSpotReturnSeriesSpec =
       ComputationTargetType.UNORDERED_CURRENCY_PAIR.specification(
           UnorderedCurrencyPair.of(payCurrency, receiveCurrency));
   requirements.add(
       new ValueRequirement(
           ValueRequirementNames.RETURN_SERIES, fxSpotReturnSeriesSpec, fxSpotConstraints));
   return requirements;
 }
 @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;
 }
  @Override
  public Set<ValueRequirement> getRequirements(
      final FunctionCompilationContext context,
      final ComputationTarget target,
      final ValueRequirement desiredValue) {
    final LegacyVanillaCDSSecurity cds = (LegacyVanillaCDSSecurity) target.getSecurity();
    final Currency ccy = cds.getNotional().getCurrency();
    final CreditCurveIdentifier isdaIdentifier = getISDACurveIdentifier(cds);
    final CreditCurveIdentifier spreadIdentifier = getSpreadCurveIdentifier(cds);

    final String isdaOffset = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_OFFSET);
    if (isdaOffset == null) {
      return null;
    }

    final String isdaCurveDate = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_DATE);
    if (isdaCurveDate == null) {
      return null;
    }

    final String isdaCurveMethod =
        desiredValue.getConstraint(ISDAFunctionConstants.ISDA_IMPLEMENTATION);
    if (isdaCurveMethod == null) {
      return null;
    }

    // isda curve
    final ValueProperties isdaProperties =
        ValueProperties.builder()
            .with(ValuePropertyNames.CURVE, isdaIdentifier.toString())
            .with(
                ValuePropertyNames.CURVE_CALCULATION_METHOD, ISDAFunctionConstants.ISDA_METHOD_NAME)
            .with(ISDAFunctionConstants.ISDA_CURVE_OFFSET, isdaOffset)
            .with(ISDAFunctionConstants.ISDA_CURVE_DATE, isdaCurveDate)
            .with(ISDAFunctionConstants.ISDA_IMPLEMENTATION, isdaCurveMethod)
            .get();
    final ValueRequirement isdaRequirment =
        new ValueRequirement(
            ValueRequirementNames.YIELD_CURVE,
            ComputationTargetType.CURRENCY,
            ccy.getUniqueId(),
            isdaProperties);

    final String quoteConvention =
        desiredValue.getConstraint(ISDAFunctionConstants.CDS_QUOTE_CONVENTION);
    if (quoteConvention == null) {
      return null;
    }

    final String bucketTenors =
        desiredValue.getConstraint(ISDAFunctionConstants.ISDA_BUCKET_TENORS);
    if (bucketTenors == null) {
      return null;
    }

    // market  spreads
    final ValueProperties spreadProperties =
        ValueProperties.builder()
            .with(ISDAFunctionConstants.CDS_QUOTE_CONVENTION, quoteConvention)
            .with(
                ValuePropertyNames.CURVE_CALCULATION_METHOD, ISDAFunctionConstants.ISDA_METHOD_NAME)
            .with(ISDAFunctionConstants.ISDA_CURVE_OFFSET, isdaOffset)
            .with(ISDAFunctionConstants.ISDA_CURVE_DATE, isdaCurveDate)
            .with(ISDAFunctionConstants.ISDA_IMPLEMENTATION, isdaCurveMethod)
            .with(ISDAFunctionConstants.ISDA_BUCKET_TENORS, bucketTenors)
            .get();
    final ValueRequirement spreadRequirment =
        new ValueRequirement(
            ValueRequirementNames.BUCKETED_SPREADS, target.toSpecification(), spreadProperties);
    final ValueRequirement pillarRequirment =
        new ValueRequirement(
            ValueRequirementNames.PILLAR_SPREADS, target.toSpecification(), spreadProperties);
    final ValueRequirement creditCurveRequirement =
        new ValueRequirement(
            ValueRequirementNames.HAZARD_RATE_CURVE, target.toSpecification(), spreadProperties);

    // get individual spread for this cds (ignore business day adjustment on either)
    final Period period =
        Period.between(
            cds.getStartDate().toLocalDate().withDayOfMonth(20),
            cds.getMaturityDate().toLocalDate().withDayOfMonth(20));
    final ValueRequirement cdsSpreadRequirement =
        new ValueRequirement(
            MarketDataRequirementNames.MARKET_VALUE,
            ComputationTargetType.PRIMITIVE,
            ExternalId.of("Tenor", period.toString()));

    final CdsRecoveryRateIdentifier recoveryRateIdentifier =
        cds.accept(new CreditSecurityToRecoveryRateVisitor(context.getSecuritySource()));
    final ValueRequirement recoveryRateRequirement =
        new ValueRequirement(
            "PX_LAST", ComputationTargetType.PRIMITIVE, recoveryRateIdentifier.getExternalId());

    return Sets.newHashSet(
        isdaRequirment,
        spreadRequirment,
        cdsSpreadRequirement,
        creditCurveRequirement,
        pillarRequirment,
        recoveryRateRequirement);
  }