@Override
 public String classifyPosition(Position position) {
   if (s_useAttributes) {
     Map<String, String> attributes = position.getAttributes();
     s_logger.warn("attributes on " + position + " = " + attributes.entrySet());
     if (attributes.containsKey(getName())) {
       return attributes.get(getName());
     } else {
       return NO_REGION;
     }
   } else {
     try {
       Security security = position.getSecurityLink().resolve(_secSource);
       ExternalId id = FinancialSecurityUtils.getRegion(security);
       if (_regionSource != null) {
         if (id != null) {
           Region highestLevelRegion = _regionSource.getHighestLevelRegion(id);
           if (highestLevelRegion != null) {
             return highestLevelRegion.getName();
           } else {
             return id.getValue();
           }
         } else if (_exchangeSource != null) {
           ExternalId exchangeId = FinancialSecurityUtils.getExchange(security);
           if (exchangeId != null) {
             Exchange exchange = _exchangeSource.getSingleExchange(exchangeId);
             if (exchange.getRegionIdBundle() != null) {
               Region highestLevelRegion =
                   _regionSource.getHighestLevelRegion(exchange.getRegionIdBundle());
               if (s_specialCountriesRegions.contains(highestLevelRegion.getName())) {
                 return highestLevelRegion.getName();
               } else {
                 Set<UniqueId> parentRegionIds = highestLevelRegion.getParentRegionIds();
                 s_logger.info("got " + highestLevelRegion + ", looking for parent");
                 String parent = findTopLevelRegion(parentRegionIds);
                 s_logger.info("parent was " + parent);
                 return parent;
               }
             } else {
               s_logger.info("Exchange " + exchange.getName() + " region bundle was null");
               return NO_REGION;
             }
           }
         }
         return NO_REGION;
       } else {
         if (id != null) {
           return id.getValue();
         } else {
           return NO_REGION;
         }
       }
     } catch (UnsupportedOperationException ex) {
       return NO_REGION;
     }
   }
 }
 @Override
 public Set<ValueSpecification> getResults(
     final FunctionCompilationContext context, final ComputationTarget target) {
   final String currency = FinancialSecurityUtils.getCurrency(target.getSecurity()).getCode();
   return Collections.singleton(
       new ValueSpecification(
           _valueRequirementName, target.toSpecification(), getResultProperties(currency)));
 }
 private ValueProperties.Builder createValueProperties(final ComputationTarget target) {
   final Security security = target.getSecurity();
   final String currency = FinancialSecurityUtils.getCurrency(security).getCode();
   final ValueProperties.Builder properties = createValueProperties();
   properties.with(ValuePropertyNames.CURRENCY, currency);
   properties.with(ValuePropertyNames.CURVE_CURRENCY, currency);
   return properties;
 }
 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 ValueProperties constraints = desiredValue.getConstraints();
   final Set<String> surfaceNames = constraints.getValues(ValuePropertyNames.SURFACE);
   if (surfaceNames == null || surfaceNames.size() != 1) {
     return null;
   }
   final Set<String> curveCalculationConfigNames =
       constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
   if (curveCalculationConfigNames == null || curveCalculationConfigNames.size() != 1) {
     return null;
   }
   final String curveCalculationConfigName = curveCalculationConfigNames.iterator().next();
   final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context);
   final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource =
       new ConfigDBCurveCalculationConfigSource(configSource);
   final MultiCurveCalculationConfig curveCalculationConfig =
       curveCalculationConfigSource.getConfig(curveCalculationConfigName);
   if (curveCalculationConfig == null) {
     s_logger.error(
         "Could not find curve calculation configuration named " + curveCalculationConfigName);
     return null;
   }
   final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity());
   if (!ComputationTargetSpecification.of(currency).equals(curveCalculationConfig.getTarget())) {
     s_logger.error(
         "Security currency and curve calculation config id were not equal; have {} and {}",
         currency,
         curveCalculationConfig.getTarget());
     return null;
   }
   final String surfaceName = surfaceNames.iterator().next();
   final Set<ValueRequirement> requirements = new HashSet<>();
   requirements.addAll(
       YieldCurveFunctionUtils.getCurveRequirements(
           curveCalculationConfig, curveCalculationConfigSource));
   requirements.add(getVolatilityRequirement(surfaceName, currency));
   final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   try {
     final Set<ValueRequirement> timeSeriesRequirements =
         _definitionConverter.getConversionTimeSeriesRequirements(
             security, security.accept(_visitor));
     if (timeSeriesRequirements == null) {
       return null;
     }
     requirements.addAll(timeSeriesRequirements);
     return requirements;
   } catch (final Exception e) {
     s_logger.error(e.getMessage());
     return null;
   }
 }
 protected ValueRequirement getCurveRequirement(
     final ComputationTarget target, final String curveName, final String curveCalculationConfig) {
   final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity());
   final ValueProperties.Builder properties =
       ValueProperties.with(ValuePropertyNames.CURVE, curveName);
   properties.with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfig);
   return new ValueRequirement(
       ValueRequirementNames.YIELD_CURVE,
       ComputationTargetSpecification.of(currency),
       properties.get());
 }
 protected SwapSecurity createUnderlying(
     final ZonedDateTime earliestMaturity, final ZonedDateTime swaptionExpiry) {
   SwapSecurity security;
   do {
     do {
       getUnderlyingGenerator().setSwationExpiry(swaptionExpiry.toLocalDate());
       security = getUnderlyingGenerator().createSecurity();
     } while (security == null);
   } while ((FinancialSecurityUtils.getCurrency(security) == null)
       || security.getMaturityDate().isBefore(earliestMaturity));
   return security;
 }
 @Override
 protected ValueProperties.Builder getResultProperties(
     final String riskFreeCurveName,
     final String creditCurveName,
     final String riskFreeCurveConfig,
     final String creditCurveConfig,
     final ComputationTarget target) {
   return super.getResultProperties(
           riskFreeCurveName, creditCurveName, riskFreeCurveConfig, creditCurveConfig, target)
       .with(
           ValuePropertyNames.CURRENCY,
           FinancialSecurityUtils.getCurrency(target.getSecurity()).getCode());
 }
Beispiel #9
0
 private ValueProperties.Builder createCurrencyValueProperties(final ComputationTarget target) {
   final Security security = target.getPosition().getSecurity();
   if (security instanceof FXOptionSecurity
       || security instanceof FXBarrierOptionSecurity
       || security instanceof FXDigitalOptionSecurity
       || security instanceof FXForwardSecurity) {
     return createValueProperties(); // TODO what to do in this case?
   }
   final Currency ccy = FinancialSecurityUtils.getCurrency(security);
   final ValueProperties.Builder properties = createValueProperties();
   properties.with(ValuePropertyNames.CURRENCY, ccy.getCode());
   return properties;
 }
 @Override
 public boolean canApplyTo(
     final FunctionCompilationContext context, final ComputationTarget target) {
   if (!(target.getTrade().getSecurity() instanceof IRFutureOptionSecurity)) {
     return false;
   }
   for (final String applicableCurrencyName : _applicableCurrencyNames) {
     if (applicableCurrencyName.equals(
         FinancialSecurityUtils.getCurrency(target.getTrade().getSecurity()).getCode())) {
       return true;
     }
   }
   return false;
 }
 @Override
 protected Set<String> getDefaultValue(
     final FunctionCompilationContext context,
     final ComputationTarget target,
     final ValueRequirement desiredValue,
     final String propertyName) {
   final String currency = FinancialSecurityUtils.getCurrency(target.getSecurity()).getCode();
   if (CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_CURVE_BUMP.equals(propertyName)) {
     return Collections.singleton(_currencyToSpreadCurveBump.get(currency));
   }
   if (CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_BUMP_TYPE.equals(propertyName)) {
     return Collections.singleton(_currencyToSpreadBumpType.get(currency));
   }
   return null;
 }
 @Override
 public Set<ValueRequirement> getRequirements(
     final FunctionCompilationContext context,
     final ComputationTarget target,
     final ValueRequirement desiredValue) {
   final ValueProperties constraints = desiredValue.getConstraints();
   final Set<String> forwardCurveNames =
       constraints.getValues(YieldCurveFunction.PROPERTY_FORWARD_CURVE);
   if (forwardCurveNames == null || forwardCurveNames.size() != 1) {
     return null;
   }
   final Set<String> fundingCurveNames =
       constraints.getValues(YieldCurveFunction.PROPERTY_FUNDING_CURVE);
   if (fundingCurveNames == null || fundingCurveNames.size() != 1) {
     return null;
   }
   final Set<String> surfaceNames = constraints.getValues(ValuePropertyNames.SURFACE);
   if (surfaceNames == null || surfaceNames.size() != 1) {
     return null;
   }
   final Set<String> curveCalculationMethods =
       constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_METHOD);
   if (curveCalculationMethods == null || curveCalculationMethods.size() != 1) {
     return null;
   }
   final String forwardCurveName = forwardCurveNames.iterator().next();
   final String fundingCurveName = fundingCurveNames.iterator().next();
   final String surfaceName = surfaceNames.iterator().next();
   final String curveCalculationMethod = curveCalculationMethods.iterator().next();
   final Set<ValueRequirement> requirements = Sets.newHashSetWithExpectedSize(4);
   final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity());
   requirements.add(
       getCurveRequirement(
           forwardCurveName,
           forwardCurveName,
           fundingCurveName,
           curveCalculationMethod,
           currency));
   requirements.add(
       getCurveRequirement(
           fundingCurveName,
           forwardCurveName,
           fundingCurveName,
           curveCalculationMethod,
           currency));
   requirements.add(getVolatilityRequirement(surfaceName, currency));
   return requirements;
 }
 @Override
 public Set<ValueRequirement> getRequirements(
     final FunctionCompilationContext context,
     final ComputationTarget target,
     final ValueRequirement desiredValue) {
   final ValueProperties constraints = desiredValue.getConstraints();
   final Set<String> curveCalculationConfigNames =
       constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
   if (curveCalculationConfigNames == null || curveCalculationConfigNames.size() != 1) {
     return null;
   }
   final String curveCalculationConfigName = curveCalculationConfigNames.iterator().next();
   final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context);
   final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource =
       new ConfigDBCurveCalculationConfigSource(configSource);
   final MultiCurveCalculationConfig curveCalculationConfig =
       curveCalculationConfigSource.getConfig(curveCalculationConfigName);
   if (curveCalculationConfig == null) {
     s_logger.error(
         "Could not find curve calculation configuration named " + curveCalculationConfigName);
     return null;
   }
   final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   final Currency currency = FinancialSecurityUtils.getCurrency(security);
   if (!currency.equals(curveCalculationConfig.getUniqueId())) {
     s_logger.error(
         "Security currency and curve calculation config id were not equal; have {} and {}",
         currency,
         curveCalculationConfig.getUniqueId());
   }
   final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
   requirements.addAll(
       YieldCurveFunctionUtils.getCurveRequirements(
           curveCalculationConfig, curveCalculationConfigSource));
   final Set<ValueRequirement> timeSeriesRequirements =
       getDerivativeTimeSeriesRequirements(
           security, security.accept(_visitor), _definitionConverter);
   if (timeSeriesRequirements == null) {
     return null;
   }
   requirements.addAll(timeSeriesRequirements);
   return requirements;
 }
 @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
 protected ValueProperties.Builder createValueProperties(
     final ComputationTarget target, final ValueRequirement desiredValue) {
   final String cubeDefinitionName =
       desiredValue.getConstraint(SurfaceAndCubePropertyNames.PROPERTY_CUBE_DEFINITION);
   final String cubeSpecificationName =
       desiredValue.getConstraint(SurfaceAndCubePropertyNames.PROPERTY_CUBE_SPECIFICATION);
   final String surfaceDefinitionName =
       desiredValue.getConstraint(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_DEFINITION);
   final String surfaceSpecificationName =
       desiredValue.getConstraint(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_SPECIFICATION);
   final String currency = FinancialSecurityUtils.getCurrency(target.getSecurity()).getCode();
   final String curveCalculationConfig =
       desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
   final String fittingMethod =
       desiredValue.getConstraint(SmileFittingPropertyNamesAndValues.PROPERTY_FITTING_METHOD);
   final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
   final String cutoff =
       desiredValue.getConstraint(SABRRightExtrapolationFunction.PROPERTY_CUTOFF_STRIKE);
   final String mu =
       desiredValue.getConstraint(
           SABRRightExtrapolationFunction.PROPERTY_TAIL_THICKNESS_PARAMETER);
   return createValueProperties()
       .with(ValuePropertyNames.CURRENCY, currency)
       .with(ValuePropertyNames.CURVE_CURRENCY, currency)
       .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfig)
       .with(ValuePropertyNames.CURVE, curveName)
       .with(SurfaceAndCubePropertyNames.PROPERTY_CUBE_DEFINITION, cubeDefinitionName)
       .with(SurfaceAndCubePropertyNames.PROPERTY_CUBE_SPECIFICATION, cubeSpecificationName)
       .with(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_DEFINITION, surfaceDefinitionName)
       .with(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_SPECIFICATION, surfaceSpecificationName)
       .with(SABRRightExtrapolationFunction.PROPERTY_CUTOFF_STRIKE, cutoff)
       .with(SABRRightExtrapolationFunction.PROPERTY_TAIL_THICKNESS_PARAMETER, mu)
       .with(SmileFittingPropertyNamesAndValues.PROPERTY_FITTING_METHOD, fittingMethod)
       .with(
           SmileFittingPropertyNamesAndValues.PROPERTY_VOLATILITY_MODEL,
           SmileFittingPropertyNamesAndValues.SABR)
       .with(ValuePropertyNames.CALCULATION_METHOD, SABRFunction.SABR_RIGHT_EXTRAPOLATION);
 }
 @Override
 protected ValueProperties.Builder getResultProperties(final ComputationTarget target) {
   final String currency =
       FinancialSecurityUtils.getCurrency(target.getTrade().getSecurity()).getCode();
   return super.getResultProperties(target).with(CURRENCY, currency);
 }
 @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);
 }
  @Override
  public SwaptionSecurity createSecurity() {
    final int optionLength = getRandom(OPTION_LENGTH);
    ZonedDateTime expiry = ZonedDateTime.now().plusMonths(optionLength);
    final SwapSecurity underlying = createUnderlying(expiry.plusMonths(2), expiry);
    final Currency currency = FinancialSecurityUtils.getCurrency(underlying);
    expiry = nextWorkingDay(expiry, currency);
    final boolean isPayer = getRandom().nextBoolean();
    final boolean isLong = getRandom().nextBoolean();
    final boolean isCashSettled = getRandom().nextBoolean();
    final ZonedDateTime settlementDate = nextWorkingDay(expiry.plusDays(2), currency);
    final Double notional =
        underlying
            .getPayLeg()
            .getNotional()
            .accept(
                new NotionalVisitor<Double>() {

                  @Override
                  public Double visitCommodityNotional(final CommodityNotional notional) {
                    return null;
                  }

                  @Override
                  public Double visitInterestRateNotional(final InterestRateNotional notional) {
                    return notional.getAmount();
                  }

                  @Override
                  public Double visitSecurityNotional(final SecurityNotional notional) {
                    return null;
                  }

                  @Override
                  public Double visitVarianceSwapNotional(final VarianceSwapNotional notional) {
                    return notional.getAmount();
                  }
                });
    if (notional == null) {
      return null;
    }
    Double rate = getRate(underlying.getPayLeg());
    if (rate == null) {
      rate = getRate(underlying.getReceiveLeg());
      if (rate == null) {
        return null;
      }
    }
    final SwaptionSecurity security =
        new SwaptionSecurity(
            isPayer,
            getSecurityPersister().storeSecurity(underlying).iterator().next(),
            isLong,
            new Expiry(expiry),
            isCashSettled,
            currency,
            notional,
            new EuropeanExerciseType(),
            settlementDate);
    security.setName(
        createName(
            currency,
            optionLength,
            (int) MONTHS.between(underlying.getEffectiveDate(), underlying.getMaturityDate()),
            notional,
            rate));
    return security;
  }
 @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 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 forwardCurveName =
       desiredValue.getConstraint(YieldCurveFunction.PROPERTY_FORWARD_CURVE);
   final String fundingCurveName =
       desiredValue.getConstraint(YieldCurveFunction.PROPERTY_FUNDING_CURVE);
   final String curveCalculationMethod =
       desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_METHOD);
   final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
   final Object forwardCurveObject =
       inputs.getValue(
           YieldCurveFunction.getCurveRequirement(
               currency,
               forwardCurveName,
               forwardCurveName,
               fundingCurveName,
               curveCalculationMethod));
   if (forwardCurveObject == null) {
     throw new OpenGammaRuntimeException("Could not get forward curve");
   }
   final Object fundingCurveObject =
       inputs.getValue(
           YieldCurveFunction.getCurveRequirement(
               currency,
               fundingCurveName,
               forwardCurveName,
               fundingCurveName,
               curveCalculationMethod));
   if (fundingCurveObject == null) {
     throw new OpenGammaRuntimeException("Could not get funding curve");
   }
   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 YieldAndDiscountCurve forwardCurve = (YieldAndDiscountCurve) forwardCurveObject;
   final YieldAndDiscountCurve fundingCurve = (YieldAndDiscountCurve) fundingCurveObject;
   final InstrumentDefinition<?> definition = security.accept(_visitor);
   final InstrumentDerivative swaption =
       definition.toDerivative(now, new String[] {fundingCurveName, forwardCurveName});
   final ValueProperties properties =
       getResultProperties(
           currency.getCode(),
           forwardCurveName,
           fundingCurveName,
           curveCalculationMethod,
           surfaceName);
   final ValueSpecification spec =
       new ValueSpecification(_valueRequirementName, target.toSpecification(), properties);
   final YieldCurveBundle curves =
       new YieldCurveBundle(
           new String[] {fundingCurveName, forwardCurveName},
           new YieldAndDiscountCurve[] {fundingCurve, forwardCurve});
   final BlackSwaptionParameters parameters =
       new BlackSwaptionParameters(
           volatilitySurface.getSurface(),
           SwaptionUtils.getSwapGenerator(security, definition, securitySource));
   final YieldCurveWithBlackSwaptionBundle data =
       new YieldCurveWithBlackSwaptionBundle(parameters, curves);
   return getResult(swaption, data, spec);
 }
 @Override
 public boolean canApplyTo(
     final FunctionCompilationContext context, final ComputationTarget target) {
   return _currencyToSpreadCurveBump.containsKey(
       FinancialSecurityUtils.getCurrency(target.getSecurity()).getCode());
 }