Package com.opengamma.financial.analytics.ircurve

Examples of com.opengamma.financial.analytics.ircurve.YieldCurveDefinition$Meta


        final int offset = Integer.parseInt(offsetString)//TODO: Is this still used???
        final Object definitionObject = inputs.getValue(ValueRequirementNames.TARGET);
        if (definitionObject == null) {
          throw new OpenGammaRuntimeException("Couldn't get interpolated yield curve specification: " + curveName);
        }
        final YieldCurveDefinition curveDefinition = (YieldCurveDefinition) definitionObject;
        final Object dataObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE_MARKET_DATA);
        if (dataObject == null) {
          throw new OpenGammaRuntimeException("Couldn't get yield curve data for " + curveName);
        }
        final SnapshotDataBundle marketData = (SnapshotDataBundle) dataObject;
        final InterpolatedYieldCurveSpecification specification = getCurveSpecification(curveDefinition, spotDate);
        final InterpolatedYieldCurveSpecificationWithSecurities specificationWithSecurities = getCurveWithSecurities(
            specification,
            executionContext,
            marketData);
        final ISDAInstrumentTypes[] instruments = new ISDAInstrumentTypes[specificationWithSecurities.getStrips().size()];
        final Period[] tenors = new Period[specificationWithSecurities.getStrips().size()];
        final double[] values = new double[specificationWithSecurities.getStrips().size()];

        Period swapIvl = null;
        int i = 0;
        for (final FixedIncomeStripWithSecurity strip : specificationWithSecurities.getStrips()) {
          final String securityType = strip.getSecurity().getSecurityType();
          if (!(securityType.equals(CashSecurity.SECURITY_TYPE) || securityType.equals(SwapSecurity.SECURITY_TYPE))) {
            throw new OpenGammaRuntimeException("ISDA curves should only use Libor and swap rates");
          }
          final Double rate = marketData.getDataPoint(strip.getSecurityIdentifier());
          if (rate == null) {
            throw new OpenGammaRuntimeException("Could not get rate for " + strip);
          }
          if (CashSecurity.SECURITY_TYPE.equals(strip.getSecurity().getSecurityType())) {
            instruments[i] = ISDAInstrumentTypes.MoneyMarket;
          } else if (SwapSecurity.SECURITY_TYPE.equals(strip.getSecurity().getSecurityType())) {
            instruments[i] = ISDAInstrumentTypes.Swap;
            swapIvl = getFixedLegPaymentTenor((SwapSecurity) strip.getSecurity());
          } else {
            throw new OpenGammaRuntimeException("Unexpected curve instument type, can only handle cash and swaps, got: " + strip.getSecurity());
          }
          tenors[i] = strip.getTenor().getPeriod();
          values[i] = rate;
          i++;
        }

        final ISDACompliantYieldCurve yieldCurve = ISDACompliantYieldCurveBuild.build(valuationDate.toLocalDate(), spotDate, instruments, tenors, values, MONEY_MARKET_DCC, SWAP_DCC, swapIvl, CURVE_DCC, badDayConv);

        final ValueProperties properties = createValueProperties()
            .with(ValuePropertyNames.CURVE, curveName)
            .with(ISDAFunctionConstants.ISDA_CURVE_OFFSET, offsetString)
            .with(ISDAFunctionConstants.ISDA_CURVE_DATE, spotDateString)
            .with(ISDAFunctionConstants.ISDA_IMPLEMENTATION, ISDAFunctionConstants.ISDA_IMPLEMENTATION_NEW)
            .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, ISDAFunctionConstants.ISDA_METHOD_NAME).get();
        final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.YIELD_CURVE, target.toSpecification(), properties);
        return Collections.singleton(new ComputedValue(spec, yieldCurve));
      }

      private Period getFixedLegPaymentTenor(final SwapSecurity swap) {
        if (swap.getReceiveLeg() instanceof FixedInterestRateLeg) {
          FixedInterestRateLeg fixLeg = (FixedInterestRateLeg) swap.getReceiveLeg();
          return PeriodFrequency.convertToPeriodFrequency(fixLeg.getFrequency()).getPeriod();
        } else if (swap.getPayLeg() instanceof FixedInterestRateLeg) {
          FixedInterestRateLeg fixLeg = (FixedInterestRateLeg) swap.getPayLeg();
          return PeriodFrequency.convertToPeriodFrequency(fixLeg.getFrequency()).getPeriod();
        } else {
          throw new OpenGammaRuntimeException("Got a swap without a fixed leg " + swap);
        }

      }

      @Override
      public ComputationTargetType getTargetType() {
        return ComputationTargetType.CURRENCY;
      }

      @Override
      public boolean canApplyTo(final FunctionCompilationContext context, final ComputationTarget target) {
        return Currency.OBJECT_SCHEME.equals(target.getUniqueId().getScheme());
      }

      @Override
      public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target) {
        @SuppressWarnings("synthetic-access")
        final ValueProperties properties = createValueProperties()
            .withAny(ValuePropertyNames.CURVE)
            .withAny(ISDAFunctionConstants.ISDA_CURVE_OFFSET)
            .withAny(ISDAFunctionConstants.ISDA_CURVE_DATE)
            .with(ISDAFunctionConstants.ISDA_IMPLEMENTATION, ISDAFunctionConstants.ISDA_IMPLEMENTATION_NEW)
            .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, ISDAFunctionConstants.ISDA_METHOD_NAME)
            .get();
        return Collections.singleton(new ValueSpecification(ValueRequirementNames.YIELD_CURVE, target.toSpecification(), properties));
      }

      @Override
      public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
        final ValueProperties constraints = desiredValue.getConstraints();
        final Set<String> curveNames = constraints.getValues(ValuePropertyNames.CURVE);
        if (curveNames == null || curveNames.size() != 1) {
          return null;
        }
        final String curveName = Iterables.getOnlyElement(curveNames);
        final ValueProperties properties = ValueProperties.builder()
            .with(ValuePropertyNames.CURVE, curveName).get();

        // look up yield curve specification - dont rely on YieldCurveSpecificationFunction as that may have been compiled before the yield curve was created
        // this is a slight performance hit over the standard curve spec handling but shouldn't be an issue
        //TODO: should use versionOf rather than latest but we dont access to the valuation clock here
        final YieldCurveDefinition curveDefinition = configSource.getLatestByName(YieldCurveDefinition.class, curveName);
        if (curveDefinition == null) {
          return null;
        }

        final Set<ValueRequirement> requirements = Sets.newHashSetWithExpectedSize(2);
        final ComputationTargetSpecification targetSpec = target.toSpecification();
        requirements.add(new ValueRequirement(ValueRequirementNames.YIELD_CURVE_MARKET_DATA, targetSpec, properties));
        requirements.add(new ValueRequirement(ValueRequirementNames.TARGET, ComputationTargetType.of(YieldCurveDefinition.class), curveDefinition.getUniqueId()));
        return requirements;
      }

      private InterpolatedYieldCurveSpecificationWithSecurities getCurveWithSecurities(final InterpolatedYieldCurveSpecification curveSpec, final FunctionExecutionContext executionContext,
                                                                                       final SnapshotDataBundle marketData) {
View Full Code Here

TOP

Related Classes of com.opengamma.financial.analytics.ircurve.YieldCurveDefinition$Meta

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.