コード例 #1
0
 static InstrumentDerivative getDerivative(
     final FinancialSecurity security,
     final ZonedDateTime now,
     final HistoricalTimeSeriesBundle timeSeries,
     final String[] curveNames,
     final InstrumentDefinition<?> definition,
     final FixedIncomeConverterDataProvider definitionConverter) {
   final InstrumentDerivative derivative;
   if (security instanceof SwapSecurity) {
     final SwapSecurity swapSecurity = (SwapSecurity) security;
     final InterestRateInstrumentType type = SwapSecurityUtils.getSwapType(swapSecurity);
     if (type == InterestRateInstrumentType.SWAP_FIXED_IBOR
         || type == InterestRateInstrumentType.SWAP_FIXED_IBOR_WITH_SPREAD
         || type == InterestRateInstrumentType.SWAP_FIXED_OIS) {
       final Frequency resetFrequency;
       if (swapSecurity.getPayLeg() instanceof FloatingInterestRateLeg) {
         resetFrequency = ((FloatingInterestRateLeg) swapSecurity.getPayLeg()).getFrequency();
       } else {
         resetFrequency = ((FloatingInterestRateLeg) swapSecurity.getReceiveLeg()).getFrequency();
       }
       derivative =
           definitionConverter.convert(
               security,
               definition,
               now,
               FixedIncomeInstrumentCurveExposureHelper.getCurveNamesForSecurity(
                   security, curveNames, resetFrequency),
               timeSeries);
     } else {
       derivative =
           definitionConverter.convert(
               security,
               definition,
               now,
               FixedIncomeInstrumentCurveExposureHelper.getCurveNamesForSecurity(
                   security, curveNames),
               timeSeries);
     }
   } else {
     derivative =
         definitionConverter.convert(
             security,
             definition,
             now,
             FixedIncomeInstrumentCurveExposureHelper.getCurveNamesForSecurity(
                 security, curveNames),
             timeSeries);
   }
   return derivative;
 }
コード例 #2
0
 @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;
   }
 }
コード例 #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 = 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);
 }
コード例 #4
0
 static Set<ValueRequirement> getDerivativeTimeSeriesRequirements(
     final FinancialSecurity security,
     final InstrumentDefinition<?> definition,
     final FixedIncomeConverterDataProvider definitionConverter) {
   return definitionConverter.getConversionTimeSeriesRequirements(security, definition);
 }