Package com.opengamma.financial.analytics.forwardcurve

Examples of com.opengamma.financial.analytics.forwardcurve.ForwardSwapCurveInstrumentProvider


  @Override
  public ForwardSwapCurveSpecification buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
    final Currency target = deserializer.fieldValueToObject(Currency.class, message.getByName(TARGET_FIELD));
    final String name = message.getString(NAME_FIELD);
    final ForwardSwapCurveInstrumentProvider provider = deserializer.fieldValueToObject(ForwardSwapCurveInstrumentProvider.class, message.getByName(INSTRUMENT_PROVIDER_FIELD));
    return new ForwardSwapCurveSpecification(name, target, provider);
  }
View Full Code Here


        }
        final ForwardSwapCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currency.toString());
        if (specification == null) {
          throw new OpenGammaRuntimeException("Couldn't find a forward swap curve specification called " + curveName + " for target " + target);
        }
        final ForwardSwapCurveInstrumentProvider provider = (ForwardSwapCurveInstrumentProvider) specification.getCurveInstrumentProvider();
        final Object dataObject = inputs.getValue(ValueRequirementNames.FORWARD_SWAP_CURVE_MARKET_DATA);
        if (dataObject == null) {
          throw new OpenGammaRuntimeException("Could not get market data");
        }
        @SuppressWarnings("unchecked")
        final Map<ExternalId, Double> data = (Map<ExternalId, Double>) dataObject;
        final String interpolatorName = desiredValue.getConstraint(PROPERTY_FORWARD_CURVE_INTERPOLATOR);
        final String leftExtrapolatorName = desiredValue.getConstraint(PROPERTY_FORWARD_CURVE_LEFT_EXTRAPOLATOR);
        final String rightExtrapolatorName = desiredValue.getConstraint(PROPERTY_FORWARD_CURVE_RIGHT_EXTRAPOLATOR);
        final String forwardTenorName = desiredValue.getConstraint(ForwardSwapCurveMarketDataFunction.PROPERTY_FORWARD_TENOR);
        final String conventionName = currency.getCode() + "_SWAP";
        final ConventionBundle convention = conventionSource.getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, conventionName));
        if (convention == null) {
          throw new OpenGammaRuntimeException("Could not get convention named " + conventionName);
        }
        final DayCount dayCount = convention.getSwapFloatingLegDayCount();
        if (dayCount == null) {
          throw new OpenGammaRuntimeException("Could not get daycount");
        }
        final Integer settlementDays = convention.getSwapFloatingLegSettlementDays();
        if (settlementDays == null) {
          throw new OpenGammaRuntimeException("Could not get number of settlement days");
        }
        final Calendar calendar = new HolidaySourceCalendarAdapter(holidaySource, currency);
        final LocalDate localNow = now.toLocalDate();
        final Period forwardPeriod = Period.parse(forwardTenorName);
        final Tenor forwardTenor = Tenor.of(forwardPeriod);
        final LocalDate forwardStart = ScheduleCalculator.getAdjustedDate(localNow.plus(forwardPeriod), settlementDays, calendar); //TODO check adjustments
        for (final Tenor tenor : definition.getTenors()) {
          final ExternalId identifier = provider.getInstrument(localNow, tenor, forwardTenor);
          if (data.containsKey(identifier)) {
            final LocalDate expiry = ScheduleCalculator.getAdjustedDate(forwardStart.plus(tenor.getPeriod()), settlementDays, calendar);
            expiries.add(dayCount.getDayCountFraction(localNow, expiry));
            forwards.add(data.get(identifier));
          }
View Full Code Here

        final ForwardSwapCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currency.toString());
        if (specification == null) {
          throw new OpenGammaRuntimeException("Couldn't find a forward swap curve specification called " + curveName + " with target " + target);
        }
        final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
        final ForwardSwapCurveInstrumentProvider provider = (ForwardSwapCurveInstrumentProvider) specification.getCurveInstrumentProvider();
        final Tenor forwardTenor = Tenor.of(Period.parse(forwardTenorName));
        for (final Tenor tenor : definition.getTenors()) {
          final ExternalId identifier = provider.getInstrument(atZDT.toLocalDate(), tenor, forwardTenor);
          requirements.add(new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier));
        }
        requirements.add(new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, provider.getSpotInstrument(forwardTenor)));
        return requirements;
      }

      @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 ValueRequirement desiredValue = desiredValues.iterator().next();
        final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
        final String forwardTenorName = desiredValue.getConstraint(PROPERTY_FORWARD_TENOR);
        final Currency currencyPair = target.getValue(PrimitiveComputationTargetType.CURRENCY);
        final ForwardSwapCurveDefinition definition = curveDefinitionSource.getDefinition(curveName, currencyPair.toString());
        if (definition == null) {
          throw new OpenGammaRuntimeException("Couldn't find a forward swap curve definition called " + curveName + " for target " + target);
        }
        final ForwardSwapCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currencyPair.toString());
        if (specification == null) {
          throw new OpenGammaRuntimeException("Couldn't find FX forward curve specification called " + curveName + " for target " + target);
        }
        final ForwardSwapCurveInstrumentProvider provider = (ForwardSwapCurveInstrumentProvider) specification.getCurveInstrumentProvider();
        final Tenor forwardTenor = Tenor.of(Period.parse(forwardTenorName));
        final ValueRequirement spotRequirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, provider.getSpotInstrument(forwardTenor));
        if (inputs.getValue(spotRequirement) == null) {
          throw new OpenGammaRuntimeException("Could not get value for spot; requirement was " + spotRequirement);
        }
        final Double spot = (Double) inputs.getValue(spotRequirement);
        final Map<ExternalId, Double> data = new HashMap<ExternalId, Double>();
        for (final Tenor tenor : definition.getTenors()) {
          final ExternalId identifier = provider.getInstrument(now.toLocalDate(), tenor, forwardTenor);
          final ValueRequirement requirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier);
          if (inputs.getValue(requirement) != null) {
            final Double spread = (Double) inputs.getValue(requirement);
            data.put(identifier, spot + spread);
          }
        }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.analytics.forwardcurve.ForwardSwapCurveInstrumentProvider

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.