@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<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;
 }
Exemple #3
0
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = snapshotClock.zonedDateTime();
   final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   final Currency payCurrency, receiveCurrency;
   if (security instanceof FXForwardSecurity) {
     final FXForwardSecurity forward = (FXForwardSecurity) security;
     payCurrency = forward.getPayCurrency();
     receiveCurrency = forward.getReceiveCurrency();
   } else {
     final NonDeliverableFXForwardSecurity ndf = (NonDeliverableFXForwardSecurity) security;
     payCurrency = ndf.getPayCurrency();
     receiveCurrency = ndf.getReceiveCurrency();
   }
   final ForexDefinition definition = (ForexDefinition) security.accept(VISITOR);
   final ValueRequirement desiredValue = desiredValues.iterator().next();
   final String payCurveName = desiredValue.getConstraint(ValuePropertyNames.PAY_CURVE);
   final String receiveCurveName = desiredValue.getConstraint(ValuePropertyNames.RECEIVE_CURVE);
   final String payCurveConfig = desiredValue.getConstraint(PAY_CURVE_CALC_CONFIG);
   final String receiveCurveConfig = desiredValue.getConstraint(RECEIVE_CURVE_CALC_CONFIG);
   final String fullPutCurveName = payCurveName + "_" + payCurrency.getCode();
   final String fullCallCurveName = receiveCurveName + "_" + receiveCurrency.getCode();
   final YieldAndDiscountCurve payFundingCurve =
       getCurve(inputs, payCurrency, payCurveName, payCurveConfig);
   final YieldAndDiscountCurve receiveFundingCurve =
       getCurve(inputs, receiveCurrency, receiveCurveName, receiveCurveConfig);
   final YieldAndDiscountCurve[] curves;
   final Map<String, Currency> curveCurrency = new HashMap<String, Currency>();
   curveCurrency.put(fullPutCurveName, payCurrency);
   curveCurrency.put(fullCallCurveName, receiveCurrency);
   final String[] allCurveNames;
   if (FXUtils.isInBaseQuoteOrder(
       payCurrency, receiveCurrency)) { // To get Base/quote in market standard order.
     curves = new YieldAndDiscountCurve[] {payFundingCurve, receiveFundingCurve};
     allCurveNames = new String[] {fullPutCurveName, fullCallCurveName};
   } else {
     curves = new YieldAndDiscountCurve[] {receiveFundingCurve, payFundingCurve};
     allCurveNames = new String[] {fullCallCurveName, fullPutCurveName};
   }
   final YieldCurveBundle yieldCurves = new YieldCurveBundle(allCurveNames, curves);
   final ValueProperties.Builder properties =
       getResultProperties(
           payCurveName, receiveCurveName, payCurveConfig, receiveCurveConfig, target);
   final ValueSpecification spec =
       new ValueSpecification(
           ValueRequirementNames.VALUE_THETA, target.toSpecification(), properties.get());
   final ConstantSpreadHorizonThetaCalculator calculator =
       ConstantSpreadHorizonThetaCalculator.getInstance();
   final MultipleCurrencyAmount theta =
       calculator.getTheta(definition, now, allCurveNames, yieldCurves, DAYS_TO_MOVE_FORWARD);
   return Collections.singleton(new ComputedValue(spec, theta));
 }
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final FXFutureSecurity security = (FXFutureSecurity) target.getSecurity();
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
   final Currency payCurrency = security.getNumerator();
   final Object payCurveObject =
       inputs.getValue(
           YieldCurveFunction.getCurveRequirement(payCurrency, _payCurveName, null, null));
   if (payCurveObject == null) {
     throw new OpenGammaRuntimeException("Could not get " + _payCurveName + " curve");
   }
   final Currency receiveCurrency = security.getDenominator();
   final Object receiveCurveObject =
       inputs.getValue(
           YieldCurveFunction.getCurveRequirement(receiveCurrency, _receiveCurveName, null, null));
   if (receiveCurveObject == null) {
     throw new OpenGammaRuntimeException("Could not get " + _receiveCurveName + " curve");
   }
   // TODO: The convention is only looked up here so that we can convert the spot rate; would be
   // better to request the spot rate using the correct currency pair in the first place
   final CurrencyPairs currencyPairs =
       OpenGammaExecutionContext.getCurrencyPairsSource(executionContext)
           .getCurrencyPairs(CurrencyPairs.DEFAULT_CURRENCY_PAIRS);
   final CurrencyPair currencyPair = currencyPairs.getCurrencyPair(payCurrency, receiveCurrency);
   final Currency currencyBase = currencyPair.getBase();
   final Object spotObject = inputs.getValue(ValueRequirementNames.SPOT_RATE);
   if (spotObject == null) {
     throw new OpenGammaRuntimeException("Could not get market data for spot rate");
   }
   double spot = (Double) spotObject;
   if (!receiveCurrency.equals(currencyBase) && receiveCurrency.equals(security.getCurrency())) {
     spot = 1. / spot;
   }
   final YieldAndDiscountCurve payCurve = (YieldAndDiscountCurve) payCurveObject;
   final YieldAndDiscountCurve receiveCurve = (YieldAndDiscountCurve) receiveCurveObject;
   final SimpleFXFutureDataBundle data =
       new SimpleFXFutureDataBundle(payCurve, receiveCurve, spot);
   final SimpleInstrument instrument = security.accept(CONVERTER).toDerivative(now);
   final CurrencyAmount pv = instrument.accept(CALCULATOR, data);
   final ValueProperties properties =
       createValueProperties()
           .with(ValuePropertyNames.PAY_CURVE, _payCurveName)
           .with(ValuePropertyNames.RECEIVE_CURVE, _receiveCurveName)
           .with(ValuePropertyNames.CURRENCY, pv.getCurrency().getCode())
           .get();
   final ValueSpecification spec =
       new ValueSpecification(
           ValueRequirementNames.PRESENT_VALUE, target.toSpecification(), properties);
   return Collections.singleton(new ComputedValue(spec, pv.getAmount()));
 }
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   final Currency currency = FinancialSecurityUtils.getCurrency(security);
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = snapshotClock.zonedDateTime();
   final HistoricalTimeSeriesBundle timeSeries =
       HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
   final ValueRequirement desiredValue = desiredValues.iterator().next();
   final String curveCalculationConfigName =
       desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
   final ConfigSource configSource = OpenGammaExecutionContext.getConfigSource(executionContext);
   final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource =
       new ConfigDBCurveCalculationConfigSource(configSource);
   final MultiCurveCalculationConfig curveCalculationConfig =
       curveCalculationConfigSource.getConfig(curveCalculationConfigName);
   if (curveCalculationConfig == null) {
     throw new OpenGammaRuntimeException(
         "Could not find curve calculation configuration named " + curveCalculationConfigName);
   }
   final String[] curveNames = curveCalculationConfig.getYieldCurveNames();
   final String[] yieldCurveNames =
       curveNames.length == 1 ? new String[] {curveNames[0], curveNames[0]} : curveNames;
   final String[] curveNamesForSecurity =
       FixedIncomeInstrumentCurveExposureHelper.getCurveNamesForSecurity(
           security, yieldCurveNames[0], yieldCurveNames[1]);
   final YieldCurveBundle bundle =
       YieldCurveFunctionUtils.getAllYieldCurves(
           inputs, curveCalculationConfig, curveCalculationConfigSource);
   final InstrumentDefinition<?> definition = security.accept(_visitor);
   if (definition == null) {
     throw new OpenGammaRuntimeException("Definition for security " + security + " was null");
   }
   final InstrumentDerivative derivative =
       getDerivative(
           security, now, timeSeries, curveNamesForSecurity, definition, _definitionConverter);
   return getComputedValues(
       derivative, bundle, security, target, curveCalculationConfigName, currency.getCode());
 }
  @Override
  public Set<ComputedValue> execute(
      FunctionExecutionContext executionContext,
      FunctionInputs inputs,
      ComputationTarget target,
      Set<ValueRequirement> desiredValues) {

    // 1. Get the expiry _time_ from the trade
    SimpleTrade trade =
        (SimpleTrade) target.getTrade(); // confirms that the ComputationTargetType == TRADE
    EquityVarianceSwapSecurity security = (EquityVarianceSwapSecurity) trade.getSecurity();
    double expiry =
        TimeCalculator.getTimeBetween(
            executionContext.getValuationClock().zonedDateTime(),
            security.getLastObservationDate());

    // ExternalId id = security.getSpotUnderlyingIdentifier();

    // 2. Get the discount curve and spot value
    Object discountObject = inputs.getValue(getDiscountRequirement(security));
    if (discountObject == null) {
      throw new OpenGammaRuntimeException("Could not get Discount Curve");
    }
    YieldAndDiscountCurve discountCurve = (YieldAndDiscountCurve) discountObject;

    Object spotObject = inputs.getValue(getSpotRequirement(security));
    if (spotObject == null) {
      throw new OpenGammaRuntimeException("Could not get Underlying's Spot value");
    }
    double spot = (Double) spotObject;

    // 3. Compute the forward
    final double discountFactor = discountCurve.getDiscountFactor(expiry);
    Validate.isTrue(
        discountFactor != 0,
        "The discount curve has returned a zero value for a discount bond. Check rates.");
    final double forward = spot / discountFactor;

    ValueSpecification valueSpec = getValueSpecification(security);
    return Collections.singleton(new ComputedValue(valueSpec, forward));
  }
  @Override
  public Set<ComputedValue> execute(
      final FunctionExecutionContext executionContext,
      final FunctionInputs inputs,
      final ComputationTarget target,
      final Set<ValueRequirement> desiredValues) {
    final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
    final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
    final String curveCalculationConfig =
        desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
    // 1. Get the expiry _time_ from the trade
    final EquityVarianceSwapSecurity security = (EquityVarianceSwapSecurity) target.getSecurity();
    final double expiry =
        TimeCalculator.getTimeBetween(
            executionContext.getValuationClock().zonedDateTime(),
            security.getLastObservationDate());

    // 2. Get the discount curve and spot value
    final Object discountObject =
        inputs.getValue(getDiscountRequirement(security, curveName, curveCalculationConfig));
    if (discountObject == null) {
      throw new OpenGammaRuntimeException("Could not get Discount Curve");
    }
    final YieldAndDiscountCurve discountCurve = (YieldAndDiscountCurve) discountObject;

    final Object spotObject = inputs.getValue(getSpotRequirement(security));
    if (spotObject == null) {
      throw new OpenGammaRuntimeException("Could not get Underlying's Spot value");
    }
    final double spot = (Double) spotObject;

    // 3. Compute the forward
    final double discountFactor = discountCurve.getDiscountFactor(expiry);
    Validate.isTrue(
        discountFactor != 0,
        "The discount curve has returned a zero value for a discount bond. Check rates.");
    final double forward = spot / discountFactor;

    final ValueSpecification valueSpec = getValueSpecification(security);
    return Collections.singleton(new ComputedValue(valueSpec, forward));
  }
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
   final Object volatilitySurfaceDataObject = inputs.getValue(_requirement);
   if (volatilitySurfaceDataObject == null) {
     throw new OpenGammaRuntimeException("Could not get " + _requirement);
   }
   @SuppressWarnings("unchecked")
   final VolatilitySurfaceData<LocalDate, Double> volatilitySurfaceData =
       (VolatilitySurfaceData<LocalDate, Double>) volatilitySurfaceDataObject;
   final int n = volatilitySurfaceData.getXs().length;
   final int m = volatilitySurfaceData.getYs().length;
   final DoubleArrayList t = new DoubleArrayList();
   final DoubleArrayList k = new DoubleArrayList();
   final DoubleArrayList sigma = new DoubleArrayList();
   final LocalDate[] xDates = volatilitySurfaceData.getXs();
   final Double[] y = volatilitySurfaceData.getYs();
   for (int i = 0; i < n; i++) {
     final Double time = DateUtils.getDifferenceInYears(now.toLocalDate(), xDates[i]);
     for (int j = 0; j < m; j++) {
       final Double strike = y[j];
       final Double vol = volatilitySurfaceData.getVolatility(xDates[i], y[j]);
       if (time != null && strike != null && vol != null) {
         t.add(time);
         k.add(strike);
         sigma.add(vol);
       }
     }
   }
   final Surface<Double, Double, Double> surface =
       InterpolatedDoublesSurface.from(
           t.toDoubleArray(), k.toDoubleArray(), sigma.toDoubleArray(), _interpolator);
   final VolatilitySurface volatilitySurface = new VolatilitySurface(surface);
   return Collections.singleton(new ComputedValue(_result, volatilitySurface));
 }
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
   final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   final Currency payCurrency = security.accept(ForexVisitors.getPayCurrencyVisitor());
   final Currency receiveCurrency = security.accept(ForexVisitors.getReceiveCurrencyVisitor());
   if (now.isAfter(security.accept(ForexVisitors.getExpiryVisitor()))) {
     throw new OpenGammaRuntimeException(
         "FX forward " + payCurrency.getCode() + "/" + receiveCurrency + " has expired");
   }
   final ValueRequirement desiredValue = desiredValues.iterator().next();
   final String payCurveName = desiredValue.getConstraint(ValuePropertyNames.PAY_CURVE);
   final String receiveCurveName = desiredValue.getConstraint(ValuePropertyNames.RECEIVE_CURVE);
   final String payCurveConfig =
       desiredValue.getConstraint(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG);
   final String receiveCurveConfig =
       desiredValue.getConstraint(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG);
   final String daysForward = desiredValue.getConstraint(PROPERTY_DAYS_TO_MOVE_FORWARD);
   final String fullPayCurveName = payCurveName + "_" + payCurrency.getCode();
   final String fullReceiveCurveName = receiveCurveName + "_" + receiveCurrency.getCode();
   final YieldAndDiscountCurve payFundingCurve =
       getPayCurve(inputs, payCurrency, payCurveName, payCurveConfig);
   final YieldAndDiscountCurve receiveFundingCurve =
       getReceiveCurve(inputs, receiveCurrency, receiveCurveName, receiveCurveConfig);
   final YieldAndDiscountCurve[] curves;
   final Map<String, Currency> curveCurrency = new HashMap<>();
   curveCurrency.put(fullPayCurveName, payCurrency);
   curveCurrency.put(fullReceiveCurveName, receiveCurrency);
   final String[] allCurveNames;
   final Object baseQuotePairsObject = inputs.getValue(ValueRequirementNames.CURRENCY_PAIRS);
   if (baseQuotePairsObject == null) {
     throw new OpenGammaRuntimeException("Could not get base/quote pair data");
   }
   final CurrencyPairs baseQuotePairs = (CurrencyPairs) baseQuotePairsObject;
   final CurrencyPair baseQuotePair = baseQuotePairs.getCurrencyPair(payCurrency, receiveCurrency);
   if (baseQuotePair == null) {
     throw new OpenGammaRuntimeException(
         "Could not get base/quote pair for currency pair ("
             + payCurrency
             + ", "
             + receiveCurrency
             + ")");
   }
   if (baseQuotePair
       .getBase()
       .equals(payCurrency)) { // To get Base/quote in market standard order.
     curves = new YieldAndDiscountCurve[] {payFundingCurve, receiveFundingCurve};
     allCurveNames = new String[] {fullPayCurveName, fullReceiveCurveName};
   } else {
     curves = new YieldAndDiscountCurve[] {receiveFundingCurve, payFundingCurve};
     allCurveNames = new String[] {fullReceiveCurveName, fullPayCurveName};
   }
   final ForexSecurityConverter converter = new ForexSecurityConverter(baseQuotePairs);
   final ForexDefinition definition = (ForexDefinition) security.accept(converter);
   final YieldCurveBundle yieldCurves = new YieldCurveBundle(allCurveNames, curves);
   final ValueProperties.Builder properties = getResultProperties(target, desiredValue);
   final ValueSpecification spec =
       new ValueSpecification(
           getValueRequirementName(), target.toSpecification(), properties.get());
   final ConstantSpreadHorizonThetaCalculator calculator =
       ConstantSpreadHorizonThetaCalculator.getInstance();
   final MultipleCurrencyAmount theta =
       calculator.getTheta(
           definition, now, allCurveNames, yieldCurves, Integer.parseInt(daysForward));
   return Collections.singleton(new ComputedValue(spec, theta));
 }
 /**
  * Gets a {@code ConventionBundleSource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static ConventionBundleSource getConventionBundleSource(
     final FunctionExecutionContext context) {
   return (ConventionBundleSource) context.get(CONVENTION_BUNDLE_SOURCE_NAME);
 }
 /**
  * Gets a {@code SecuritySource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static SecuritySource getSecuritySource(final FunctionExecutionContext context) {
   return context.getSecuritySource();
 }
 /**
  * Gets a {@code HistoricalTimeSeriesSource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static HistoricalTimeSeriesSource getHistoricalTimeSeriesSource(
     final FunctionExecutionContext context) {
   return (HistoricalTimeSeriesSource) context.get(HISTORICAL_TIME_SERIES_SOURCE_NAME);
 }
 public static OverrideOperationCompiler getOverrideOperationCompiler(
     final FunctionExecutionContext context) {
   return (OverrideOperationCompiler) context.get(OVERRIDE_OPERATION_COMPILER_NAME);
 }
 /**
  * Gets a {@code ConfigSource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static ConfigSource getConfigSource(final FunctionExecutionContext context) {
   return (ConfigSource) context.get(CONFIG_SOURCE_NAME);
 }
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = snapshotClock.zonedDateTime();
   final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   final InstrumentDefinition<InstrumentDerivative> definition =
       (InstrumentDefinition<InstrumentDerivative>) security.accept(VISITOR);
   final Currency putCurrency = security.accept(ForexVisitors.getPutCurrencyVisitor());
   final Currency callCurrency = security.accept(ForexVisitors.getCallCurrencyVisitor());
   final ValueRequirement desiredValue = desiredValues.iterator().next();
   final String putCurveName = desiredValue.getConstraint(PROPERTY_PUT_CURVE);
   final String callCurveName = desiredValue.getConstraint(PROPERTY_CALL_CURVE);
   final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
   final String putForwardCurveName = desiredValue.getConstraint(PROPERTY_PUT_FORWARD_CURVE);
   final String callForwardCurveName = desiredValue.getConstraint(PROPERTY_CALL_FORWARD_CURVE);
   final String putCurveCalculationMethod =
       desiredValue.getConstraint(PROPERTY_PUT_CURVE_CALCULATION_METHOD);
   final String callCurveCalculationMethod =
       desiredValue.getConstraint(PROPERTY_CALL_CURVE_CALCULATION_METHOD);
   final String interpolatorName =
       desiredValue.getConstraint(InterpolatedDataProperties.X_INTERPOLATOR_NAME);
   final String leftExtrapolatorName =
       desiredValue.getConstraint(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME);
   final String rightExtrapolatorName =
       desiredValue.getConstraint(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME);
   final String spread = desiredValue.getConstraint(PROPERTY_CALL_SPREAD_VALUE);
   final double spreadValue = Double.parseDouble(spread);
   final String fullPutCurveName = putCurveName + "_" + putCurrency.getCode();
   final String fullCallCurveName = callCurveName + "_" + callCurrency.getCode();
   final String[] curveNames;
   if (FXUtils.isInBaseQuoteOrder(
       putCurrency, callCurrency)) { // To get Base/quote in market standard order.
     curveNames = new String[] {fullPutCurveName, fullCallCurveName};
   } else {
     curveNames = new String[] {fullCallCurveName, fullPutCurveName};
   }
   final YieldAndDiscountCurve putFundingCurve = getCurve(inputs, putCurrency, putCurveName);
   final YieldAndDiscountCurve callFundingCurve = getCurve(inputs, callCurrency, callCurveName);
   final YieldAndDiscountCurve[] curves;
   final Map<String, Currency> curveCurrency = new HashMap<String, Currency>();
   curveCurrency.put(fullPutCurveName, putCurrency);
   curveCurrency.put(fullCallCurveName, callCurrency);
   final String[] allCurveNames;
   final Currency ccy1;
   final Currency ccy2;
   if (FXUtils.isInBaseQuoteOrder(
       putCurrency, callCurrency)) { // To get Base/quote in market standard order.
     ccy1 = putCurrency;
     ccy2 = callCurrency;
     curves = new YieldAndDiscountCurve[] {putFundingCurve, callFundingCurve};
     allCurveNames = new String[] {fullPutCurveName, fullCallCurveName};
   } else {
     curves = new YieldAndDiscountCurve[] {callFundingCurve, putFundingCurve};
     allCurveNames = new String[] {fullCallCurveName, fullPutCurveName};
     ccy1 = callCurrency;
     ccy2 = putCurrency;
   }
   final InstrumentDerivative fxOption = definition.toDerivative(now, curveNames);
   final YieldCurveBundle yieldCurves = new YieldCurveBundle(allCurveNames, curves);
   final Object spotObject = inputs.getValue(ValueRequirementNames.SPOT_RATE);
   if (spotObject == null) {
     throw new OpenGammaRuntimeException("Could not get spot rate");
   }
   final double spot = (Double) spotObject;
   final ValueRequirement fxVolatilitySurfaceRequirement =
       getSurfaceRequirement(
           surfaceName,
           putCurrency,
           callCurrency,
           interpolatorName,
           leftExtrapolatorName,
           rightExtrapolatorName);
   final Object volatilitySurfaceObject = inputs.getValue(fxVolatilitySurfaceRequirement);
   if (volatilitySurfaceObject == null) {
     throw new OpenGammaRuntimeException("Could not get " + fxVolatilitySurfaceRequirement);
   }
   final SmileDeltaTermStructureParametersStrikeInterpolation smiles =
       (SmileDeltaTermStructureParametersStrikeInterpolation) volatilitySurfaceObject;
   final FXMatrix fxMatrix = new FXMatrix(ccy1, ccy2, spot);
   final ValueProperties.Builder properties =
       getResultProperties(
           putCurveName,
           putForwardCurveName,
           putCurveCalculationMethod,
           callCurveName,
           callForwardCurveName,
           callCurveCalculationMethod,
           surfaceName,
           spread,
           interpolatorName,
           leftExtrapolatorName,
           rightExtrapolatorName,
           target);
   final ValueSpecification spec =
       new ValueSpecification(_valueRequirementName, target.toSpecification(), properties.get());
   final YieldCurveBundle curvesWithFX =
       new YieldCurveBundle(fxMatrix, curveCurrency, yieldCurves.getCurvesMap());
   final SmileDeltaTermStructureDataBundle smileBundle =
       new SmileDeltaTermStructureDataBundle(curvesWithFX, smiles, Pair.of(ccy1, ccy2));
   return getResult(fxOption, spreadValue, smileBundle, spec);
 }
 /**
  * Gets a {@code CurveCalculationConfigSource} from the context.
  *
  * @param context the context to examine, not null
  * @return the curve config source, null if not found
  */
 public static CurveCalculationConfigSource getCurveCalculationConfigSource(
     final FunctionExecutionContext context) {
   return (CurveCalculationConfigSource) context.get(CURVE_CALCULATION_CONFIG_NAME);
 }
 /**
  * Stores a {@code CurveCalculationConfigSource} in the context.
  *
  * @param context the context to store in, not null
  * @param curveConfigSource the curve config source to store, not null
  */
 public static void setCurveCalculationConfigSource(
     final FunctionExecutionContext context,
     final CurveCalculationConfigSource curveConfigSource) {
   context.put(CURVE_CALCULATION_CONFIG_NAME, curveConfigSource);
 }
 /**
  * Stores a {@code ConventionBundleSource} in the context.
  *
  * @param context the context to store in, not null
  * @param conventionBundleSource the value to store, not null
  */
 public static void setConventionBundleSource(
     final FunctionExecutionContext context, final ConventionBundleSource conventionBundleSource) {
   context.put(CONVENTION_BUNDLE_SOURCE_NAME, conventionBundleSource);
 }
 /**
  * Stores a {@code ConfigSource} in the context.
  *
  * @param context the context to store in, not null
  * @param configSource the value to store, not null
  */
 public static void setConfigSource(
     final FunctionExecutionContext context, final ConfigSource configSource) {
   context.put(CONFIG_SOURCE_NAME, configSource);
 }
 /**
  * Gets a {@code RegionSource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static RegionSource getRegionSource(final FunctionExecutionContext context) {
   return (RegionSource) context.get(REGION_SOURCE_NAME);
 }
 public static void setOverrideOperationCompiler(
     final FunctionExecutionContext context,
     final OverrideOperationCompiler overrideOperationCompiler) {
   context.put(OVERRIDE_OPERATION_COMPILER_NAME, overrideOperationCompiler);
 }
 /**
  * Stores a {@code RegionSource} in the context.
  *
  * @param context the context to store in, not null
  * @param regionSource the value to store, not null
  */
 public static void setRegionSource(
     final FunctionExecutionContext context, final RegionSource regionSource) {
   context.put(REGION_SOURCE_NAME, regionSource);
 }
 /**
  * Stores a {@code HistoricalTimeSeriesSource} in the context.
  *
  * @param context the context to store in, not null
  * @param source the value to store, not null
  */
 public static void setHistoricalTimeSeriesSource(
     final FunctionExecutionContext context, final HistoricalTimeSeriesSource source) {
   context.put(HISTORICAL_TIME_SERIES_SOURCE_NAME, source);
 }
 /**
  * Gets a {@code HolidaySource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static HolidaySource getHolidaySource(final FunctionExecutionContext context) {
   return (HolidaySource) context.get(HOLIDAY_SOURCE_NAME);
 }
 /**
  * Stores a {@code SecuritySource} in the context.
  *
  * @param context the context to store in, not null
  * @param securitySource the value to store, not null
  */
 public static void setSecuritySource(
     final FunctionExecutionContext context, final SecuritySource securitySource) {
   context.setSecuritySource(securitySource);
 }
 /**
  * Stores a {@code HolidaySource} in the context.
  *
  * @param context the context to store in, not null
  * @param holidaySource the value to store, not null
  */
 public static void setHolidaySource(
     final FunctionExecutionContext context, final HolidaySource holidaySource) {
   context.put(HOLIDAY_SOURCE_NAME, holidaySource);
 }
  @Override
  public Set<ComputedValue> execute(
      final FunctionExecutionContext executionContext,
      final FunctionInputs inputs,
      final ComputationTarget target,
      final Set<ValueRequirement> desiredValues)
      throws AsynchronousExecution {
    final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
    final ValueRequirement requirement = desiredValues.iterator().next();
    final ValueProperties properties = requirement.getConstraints().copy().get();

    final LegacyVanillaCDSSecurity security = (LegacyVanillaCDSSecurity) target.getSecurity();
    // LegacyVanillaCreditDefaultSwapDefinition cds =
    // _converter.visitLegacyVanillaCDSSecurity(security);
    final ValueRequirement desiredValue = desiredValues.iterator().next(); // all same constraints

    final String quoteConventionString =
        desiredValue.getConstraint(ISDAFunctionConstants.CDS_QUOTE_CONVENTION);
    final StandardCDSQuotingConvention quoteConvention =
        StandardCDSQuotingConvention.parse(quoteConventionString);

    final CdsRecoveryRateIdentifier recoveryRateIdentifier =
        security.accept(
            new CreditSecurityToRecoveryRateVisitor(executionContext.getSecuritySource()));
    Object recoveryRateObject =
        inputs.getValue(
            new ValueRequirement(
                "PX_LAST",
                ComputationTargetType.PRIMITIVE,
                recoveryRateIdentifier.getExternalId()));
    if (recoveryRateObject == null) {
      throw new OpenGammaRuntimeException("Could not get recovery rate");
      // s_logger.warn("Could not get recovery rate, defaulting to 0.4: " + recoveryRateIdentifier);
      // recoveryRateObject = 0.4;
    }
    final double recoveryRate = (Double) recoveryRateObject;

    // get the isda curve
    final Object isdaObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE);
    if (isdaObject == null) {
      throw new OpenGammaRuntimeException("Couldn't get isda curve");
    }
    final ISDACompliantYieldCurve yieldCurve = (ISDACompliantYieldCurve) isdaObject;

    // spreads
    NodalTenorDoubleCurve spreadObject =
        (NodalTenorDoubleCurve) inputs.getValue(ValueRequirementNames.BUCKETED_SPREADS);
    if (spreadObject == null) {
      throw new OpenGammaRuntimeException("Unable to get spreads");
    }
    final double[] spreads = ArrayUtils.toPrimitive(spreadObject.getYData());
    // final String pillarString = IMMDateGenerator.isIMMDate(security.getMaturityDate()) ?
    // requirement.getConstraint(ISDAFunctionConstants.ISDA_BUCKET_TENORS) :
    // ISDACompliantCreditCurveFunction.NON_IMM_PILLAR_TENORS;
    final ZonedDateTime[] bucketDates =
        SpreadCurveFunctions.getPillarDates(now, spreadObject.getXData());
    final CDSQuoteConvention[] quotes =
        SpreadCurveFunctions.getQuotes(
            security.getMaturityDate(), spreads, security.getParSpread(), quoteConvention, false);

    // spreads
    NodalTenorDoubleCurve pillarObject =
        (NodalTenorDoubleCurve) inputs.getValue(ValueRequirementNames.PILLAR_SPREADS);
    if (pillarObject == null) {
      throw new OpenGammaRuntimeException("Unable to get pillars");
    }

    // CDS analytics for credit curve (possible performance improvement if earlier result obtained)
    // final LegacyVanillaCreditDefaultSwapDefinition curveCDS = cds.withStartDate(now);
    // security.setStartDate(now); // needed for curve instruments
    final CDSAnalytic[] bucketCDSs = new CDSAnalytic[bucketDates.length];
    for (int i = 0; i < bucketCDSs.length; i++) {
      // security.setMaturityDate(bucketDates[i]);
      final CDSAnalyticVisitor visitor =
          new CDSAnalyticVisitor(
              now.toLocalDate(),
              _holidaySource,
              _regionSource,
              security.getStartDate().toLocalDate(),
              bucketDates[i].toLocalDate(),
              recoveryRate);
      bucketCDSs[i] = security.accept(visitor);
    }

    final ZonedDateTime[] pillarDates =
        SpreadCurveFunctions.getPillarDates(now, pillarObject.getXData());
    final CDSAnalytic[] pillarCDSs = new CDSAnalytic[pillarDates.length];
    for (int i = 0; i < pillarCDSs.length; i++) {
      // security.setMaturityDate(bucketDates[i]);
      final CDSAnalyticVisitor visitor =
          new CDSAnalyticVisitor(
              now.toLocalDate(),
              _holidaySource,
              _regionSource,
              security.getStartDate().toLocalDate(),
              pillarDates[i].toLocalDate(),
              recoveryRate);
      pillarCDSs[i] = security.accept(visitor);
    }

    final ISDACompliantCreditCurve creditCurve =
        (ISDACompliantCreditCurve) inputs.getValue(ValueRequirementNames.HAZARD_RATE_CURVE);
    if (creditCurve == null) {
      throw new OpenGammaRuntimeException("Couldnt get credit curve");
    }

    // final CDSAnalytic analytic = CDSAnalyticConverter.create(cds, now.toLocalDate());
    final CDSAnalyticVisitor visitor =
        new CDSAnalyticVisitor(now.toLocalDate(), _holidaySource, _regionSource, recoveryRate);
    final CDSAnalytic analytic = security.accept(visitor);
    final BuySellProtection buySellProtection =
        security.isBuy() ? BuySellProtection.BUY : BuySellProtection.SELL;
    //    final String term = new Tenor(Period.between(security.getStartDate().toLocalDate(),
    // security.getMaturityDate().toLocalDate())).getPeriod().toString();
    //    final Double cdsQuoteDouble = (Double) inputs.getValue(new
    // ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,
    //        ComputationTargetType.PRIMITIVE, ExternalId.of("Tenor", term)));
    final Double cdsQuoteDouble = (Double) inputs.getValue(MarketDataRequirementNames.MARKET_VALUE);
    if (cdsQuoteDouble == null) {
      throw new OpenGammaRuntimeException("Couldn't get spread for " + security);
    }
    final CDSQuoteConvention quote =
        SpreadCurveFunctions.getQuotes(
            security.getMaturityDate(),
            new double[] {cdsQuoteDouble},
            security.getParSpread(),
            quoteConvention,
            true)[0];

    boolean isNonIMMFAndFromPUF =
        !IMMDateLogic.isIMMDate(security.getMaturityDate().toLocalDate())
            && quote instanceof PointsUpFront;
    boolean isNonIMMAndFromSpread =
        !IMMDateLogic.isIMMDate(security.getMaturityDate().toLocalDate())
            && (quote instanceof QuotedSpread || quote instanceof ParSpread);
    int buySellPremiumFactor = security.isBuy() ? -1 : 1;

    final double notional = security.getNotional().getAmount();
    final double coupon = security.getParSpread() * ONE_BPS;
    final PointsUpFront puf =
        getPointsUpfront(quote, buySellProtection, yieldCurve, analytic, creditCurve);
    final double accruedPremiumPrim =
        isNonIMMAndFromSpread || isNonIMMFAndFromPUF ? 0 : analytic.getAccruedPremium(coupon);
    //    final double accruedPremium = isNonIMMAndFromSpread || isNonIMMFAndFromPUF ? 0 :
    // analytic.getAccruedPremium(coupon) * notional * buySellPremiumFactor;
    final double accruedPremium =
        isNonIMMAndFromSpread || isNonIMMFAndFromPUF
            ? 0
            : accruedPremiumPrim * notional * buySellPremiumFactor;
    final int accruedDays =
        isNonIMMAndFromSpread || isNonIMMFAndFromPUF ? 0 : analytic.getAccuredDays();
    final double quotedSpread =
        getQuotedSpread(quote, puf, buySellProtection, yieldCurve, analytic).getQuotedSpread();
    final double upfrontAmount =
        isNonIMMAndFromSpread
            ? 0
            : getUpfrontAmount(analytic, puf, notional, accruedPremiumPrim, buySellProtection);
    final double cleanPV = puf.getPointsUpFront() * notional;
    final double principal = isNonIMMAndFromSpread ? 0 : cleanPV;
    final double cleanPrice = getCleanPrice(puf);
    final TenorLabelledMatrix1D bucketedCS01 =
        getBucketedCS01(
            analytic,
            bucketCDSs,
            spreadObject.getXData(),
            quote,
            notional,
            yieldCurve,
            creditCurve);
    final double parallelCS01 =
        getParallelCS01(
            quote,
            analytic,
            yieldCurve,
            notional,
            pillarCDSs,
            ArrayUtils.toPrimitive(pillarObject.getYData()));

    final Set<ComputedValue> results = Sets.newHashSetWithExpectedSize(_valueRequirements.length);
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.ACCRUED_PREMIUM, target.toSpecification(), properties),
            accruedPremium));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.ACCRUED_DAYS, target.toSpecification(), properties),
            accruedDays));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.QUOTED_SPREAD, target.toSpecification(), properties),
            quotedSpread / ONE_BPS));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.UPFRONT_AMOUNT, target.toSpecification(), properties),
            upfrontAmount));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.DIRTY_PRESENT_VALUE, target.toSpecification(), properties),
            upfrontAmount));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.CLEAN_PRESENT_VALUE, target.toSpecification(), properties),
            cleanPV));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.PRINCIPAL, target.toSpecification(), properties),
            principal));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.CLEAN_PRICE, target.toSpecification(), properties),
            cleanPrice));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.BUCKETED_CS01, target.toSpecification(), properties),
            bucketedCS01));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.PARALLEL_CS01, target.toSpecification(), properties),
            parallelCS01));
    results.add(
        new ComputedValue(
            new ValueSpecification(
                ValueRequirementNames.POINTS_UPFRONT, target.toSpecification(), properties),
            puf.getPointsUpFront()));
    return results;
  }
 /**
  * Gets a {@code ExchangeSource} from the context.
  *
  * @param context the context to examine, not null
  * @return the value, null if not found
  */
 public static ExchangeSource getExchangeSource(final FunctionExecutionContext context) {
   return (ExchangeSource) context.get(EXCHANGE_SOURCE_NAME);
 }
 @Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final Clock snapshotClock = executionContext.getValuationClock();
   final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
   final SecuritySource securitySource =
       OpenGammaExecutionContext.getSecuritySource(executionContext);
   final SwaptionSecurity security = (SwaptionSecurity) target.getSecurity();
   final ValueRequirement desiredValue = desiredValues.iterator().next();
   final Currency currency = FinancialSecurityUtils.getCurrency(security);
   final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
   final String curveCalculationConfigName =
       desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
   final ConfigSource configSource = OpenGammaExecutionContext.getConfigSource(executionContext);
   final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource =
       new ConfigDBCurveCalculationConfigSource(configSource);
   final MultiCurveCalculationConfig curveCalculationConfig =
       curveCalculationConfigSource.getConfig(curveCalculationConfigName);
   if (curveCalculationConfig == null) {
     throw new OpenGammaRuntimeException(
         "Could not find curve calculation configuration named " + curveCalculationConfigName);
   }
   String[] curveNames = curveCalculationConfig.getYieldCurveNames(); // TODO
   if (curveNames.length == 1) {
     curveNames = new String[] {curveNames[0], curveNames[0]};
   }
   final String[] fullCurveNames = new String[curveNames.length];
   for (int i = 0; i < curveNames.length; i++) {
     fullCurveNames[i] = curveNames[i] + "_" + currency.getCode();
   }
   final YieldCurveBundle curves =
       YieldCurveFunctionUtils.getYieldCurves(inputs, curveCalculationConfig);
   final Object volatilitySurfaceObject =
       inputs.getValue(getVolatilityRequirement(surfaceName, currency));
   if (volatilitySurfaceObject == null) {
     throw new OpenGammaRuntimeException("Could not get volatility surface");
   }
   final VolatilitySurface volatilitySurface = (VolatilitySurface) volatilitySurfaceObject;
   if (!(volatilitySurface.getSurface() instanceof InterpolatedDoublesSurface)) {
     throw new OpenGammaRuntimeException(
         "Expecting an InterpolatedDoublesSurface; got "
             + volatilitySurface.getSurface().getClass());
   }
   final InstrumentDefinition<?> definition = security.accept(_visitor);
   final HistoricalTimeSeriesBundle timeSeries =
       HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
   final InstrumentDerivative swaption =
       _definitionConverter.convert(security, definition, now, fullCurveNames, timeSeries);
   final ValueProperties properties =
       getResultProperties(currency.getCode(), curveCalculationConfigName, surfaceName);
   final ValueSpecification spec =
       new ValueSpecification(_valueRequirementName, target.toSpecification(), properties);
   final BlackFlatSwaptionParameters parameters =
       new BlackFlatSwaptionParameters(
           volatilitySurface.getSurface(),
           SwaptionUtils.getSwapGenerator(security, definition, securitySource));
   final YieldCurveWithBlackSwaptionBundle data =
       new YieldCurveWithBlackSwaptionBundle(parameters, curves);
   return getResult(swaption, data, spec);
 }
 /**
  * Stores a {@code ExchangeSource} in the context.
  *
  * @param context the context to store in, not null
  * @param exchangeSource the value to store, not null
  */
 public static void setExchangeSource(
     final FunctionExecutionContext context, final ExchangeSource exchangeSource) {
   context.put(EXCHANGE_SOURCE_NAME, exchangeSource);
 }