Exemple #1
0
 public static ConfigMaster populateVolatilitySurfaceConfigMaster(
     final ConfigMaster configMaster) {
   populateVolatilitySurfaceSpecifications(
       configMaster, UnorderedCurrencyPair.of(Currency.EUR, Currency.USD), "EURUSD");
   populateVolatilitySurfaceDefinitions(
       configMaster, UnorderedCurrencyPair.of(Currency.EUR, Currency.USD));
   return configMaster;
 }
 @Override
 public boolean canApplyTo(
     final FunctionCompilationContext context, final ComputationTarget target) {
   final UnorderedCurrencyPair ccy = (UnorderedCurrencyPair) target.getValue();
   String currencyPair = ccy.getFirstCurrency().getCode() + ccy.getSecondCurrency().getCode();
   if (getAllCurrencyPairs().contains(currencyPair)) {
     return true;
   }
   currencyPair = ccy.getSecondCurrency().getCode() + ccy.getFirstCurrency().getCode();
   return getAllCurrencyPairs().contains(currencyPair);
 }
 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 FinancialSecurity security = (FinancialSecurity) target.getSecurity();
   final ValueProperties constraints = desiredValue.getConstraints();
   final Set<String> putCurveNames = constraints.getValues(PROPERTY_PUT_CURVE);
   if (putCurveNames == null || putCurveNames.size() != 1) {
     return null;
   }
   final Set<String> callCurveNames = constraints.getValues(PROPERTY_CALL_CURVE);
   if (callCurveNames == null || callCurveNames.size() != 1) {
     return null;
   }
   final Set<String> surfaceNames = constraints.getValues(ValuePropertyNames.SURFACE);
   if (surfaceNames == null || surfaceNames.size() != 1) {
     return null;
   }
   final Set<String> putForwardCurveNames = constraints.getValues(PROPERTY_PUT_FORWARD_CURVE);
   if (putForwardCurveNames == null || putForwardCurveNames.size() != 1) {
     return null;
   }
   final Set<String> callForwardCurveNames = constraints.getValues(PROPERTY_CALL_FORWARD_CURVE);
   if (callForwardCurveNames == null || callForwardCurveNames.size() != 1) {
     return null;
   }
   final Set<String> putCurveCalculationMethods =
       constraints.getValues(PROPERTY_PUT_CURVE_CALCULATION_METHOD);
   if (putCurveCalculationMethods == null || putCurveCalculationMethods.size() != 1) {
     return null;
   }
   final Set<String> callCurveCalculationMethods =
       constraints.getValues(PROPERTY_CALL_CURVE_CALCULATION_METHOD);
   if (callCurveCalculationMethods == null || callCurveCalculationMethods.size() != 1) {
     return null;
   }
   final Set<String> interpolatorNames =
       constraints.getValues(InterpolatedDataProperties.X_INTERPOLATOR_NAME);
   if (interpolatorNames == null || interpolatorNames.size() != 1) {
     return null;
   }
   final Set<String> leftExtrapolatorNames =
       constraints.getValues(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME);
   if (leftExtrapolatorNames == null || leftExtrapolatorNames.size() != 1) {
     return null;
   }
   final Set<String> rightExtrapolatorNames =
       constraints.getValues(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME);
   if (rightExtrapolatorNames == null || rightExtrapolatorNames.size() != 1) {
     return null;
   }
   final Set<String> spreads = constraints.getValues(PROPERTY_CALL_SPREAD_VALUE);
   if (spreads == null || spreads.size() != 1) {
     return null;
   }
   final String putCurveName = putCurveNames.iterator().next();
   final String callCurveName = callCurveNames.iterator().next();
   final String putForwardCurveName = putForwardCurveNames.iterator().next();
   final String callForwardCurveName = callForwardCurveNames.iterator().next();
   final String putCurveCalculationMethod = putCurveCalculationMethods.iterator().next();
   final String callCurveCalculationMethod = callCurveCalculationMethods.iterator().next();
   final String surfaceName = surfaceNames.iterator().next();
   final String interpolatorName = interpolatorNames.iterator().next();
   final String leftExtrapolatorName = leftExtrapolatorNames.iterator().next();
   final String rightExtrapolatorName = rightExtrapolatorNames.iterator().next();
   final Currency putCurrency = security.accept(ForexVisitors.getPutCurrencyVisitor());
   final Currency callCurrency = security.accept(ForexVisitors.getCallCurrencyVisitor());
   final ValueRequirement putFundingCurve =
       getCurveRequirement(
           putCurveName,
           putForwardCurveName,
           putCurveName,
           putCurveCalculationMethod,
           putCurrency);
   final ValueRequirement callFundingCurve =
       getCurveRequirement(
           callCurveName,
           callForwardCurveName,
           callCurveName,
           callCurveCalculationMethod,
           callCurrency);
   final ValueRequirement fxVolatilitySurface =
       getSurfaceRequirement(
           surfaceName,
           putCurrency,
           callCurrency,
           interpolatorName,
           leftExtrapolatorName,
           rightExtrapolatorName);
   final ValueRequirement spotRequirement =
       new ValueRequirement(
           ValueRequirementNames.SPOT_RATE, UnorderedCurrencyPair.of(callCurrency, putCurrency));
   return Sets.newHashSet(putFundingCurve, callFundingCurve, fxVolatilitySurface, spotRequirement);
 }
 @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;
 }