Package com.opengamma.financial.analytics.ircurve

Examples of com.opengamma.financial.analytics.ircurve.InterpolatedYieldCurveSpecificationBuilder


    final Set<ExternalId> externalIds = newHashSet();
    for (final String name : names) {
      s_logger.info("Processing curve " + name);
      final YieldCurveDefinition curveDefinition = configSource.getSingle(YieldCurveDefinition.class, name, VersionCorrection.LATEST);
      if (curveDefinition != null) {
        final InterpolatedYieldCurveSpecificationBuilder builder = new ConfigDBInterpolatedYieldCurveSpecificationBuilder(configSource);
        for (final LocalDate date : dates) {
          s_logger.info("Processing curve date " + date);
          final InterpolatedYieldCurveSpecification curveSpec = builder.buildCurve(date, curveDefinition);
          for (final FixedIncomeStripWithIdentifier strip : curveSpec.getStrips()) {
            s_logger.info("Processing strip " + strip.getSecurity());
            externalIds.add(strip.getSecurity());
          }
        }
View Full Code Here


    final Set<ExternalIdBundle> externalIds = newHashSet();
    for (final String name : names) {
      s_logger.info("Processing curve " + name);
      final YieldCurveDefinition curveDefinition = configSource.getSingle(YieldCurveDefinition.class, name, VersionCorrection.LATEST);
      if (curveDefinition != null) {
        final InterpolatedYieldCurveSpecificationBuilder builder = new ConfigDBInterpolatedYieldCurveSpecificationBuilder(configSource);
        for (final LocalDate date : dates) {
          s_logger.info("Processing curve date " + date);
          final InterpolatedYieldCurveSpecification curveSpec = builder.buildCurve(date, curveDefinition);
          for (final FixedIncomeStripWithIdentifier strip : curveSpec.getStrips()) {
            s_logger.info("Processing strip " + strip.getSecurity());
            if (strip.getStrip().getInstrumentType().equals(StripInstrumentType.FUTURE)) {
              externalIds.add(ExternalIdBundle.of(strip.getSecurity()));
            }
View Full Code Here

    final Set<ExternalId> externalIds = newHashSet();
    for (final String name : names) {
      s_logger.info("Processing curve " + name);
      YieldCurveDefinition curveDefinition = configSource.getSingle(YieldCurveDefinition.class, name, VersionCorrection.LATEST);
      if (curveDefinition != null) {
        InterpolatedYieldCurveSpecificationBuilder builder = new ConfigDBInterpolatedYieldCurveSpecificationBuilder(configSource);
        for (LocalDate date : dates) {
          s_logger.info("Processing curve date " + date);
          try {
            final InterpolatedYieldCurveSpecification curveSpec = builder.buildCurve(date, curveDefinition);
            for (final FixedIncomeStripWithIdentifier strip : curveSpec.getStrips()) {
              s_logger.info("Processing strip " + strip.getSecurity());
              externalIds.add(strip.getSecurity());
            }
          } catch (final Throwable t) {
View Full Code Here

   */
  private Set<ExternalId> getCurveFutureExternalIds(final ConfigSource configSource, final Collection<YieldCurveDefinition> curveDefs, final List<LocalDate> dates) {
    final Set<ExternalId> externalIds = newHashSet();
    for (final YieldCurveDefinition curveDefinition : curveDefs) {
      if (curveDefinition != null) {
        InterpolatedYieldCurveSpecificationBuilder builder = new ConfigDBInterpolatedYieldCurveSpecificationBuilder(configSource);
        for (LocalDate date : dates) {
          if (isVerbose()) {
            System.out.println("Processing curve " + curveDefinition.getName() + " for date " + date);
          }
          try {
            final InterpolatedYieldCurveSpecification curveSpec = builder.buildCurve(date, curveDefinition);
            for (final FixedIncomeStripWithIdentifier strip : curveSpec.getStrips()) {
              s_logger.info("Processing strip " + strip.getSecurity());
              if (strip.getInstrumentType() == StripInstrumentType.FUTURE) {
                externalIds.add(strip.getSecurity());
              }
View Full Code Here

   * @param repo  the component repository, not null
   * @param configuration  the remaining configuration, not null
   */
  @Override
  public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) {
    InterpolatedYieldCurveSpecificationBuilder builder = createInterpolatedYieldCurveSpecificationBuilder(repo);
   
    ComponentInfo info = new ComponentInfo(InterpolatedYieldCurveSpecificationBuilder.class, getClassifier());
    info.addAttribute(ComponentInfoAttributes.LEVEL, 1);
    info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteInterpolatedYieldCurveSpecificationBuilder.class);
    repo.registerComponent(info, builder);
View Full Code Here

  @Override
  public CompiledFunctionDefinition compile(final FunctionCompilationContext compilationContext, final Instant atInstant) {
    final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
    final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(compilationContext);
    final InterpolatedYieldCurveSpecificationBuilder curveSpecBuilder = new ConfigDBInterpolatedYieldCurveSpecificationBuilder(configSource);
    return new AbstractInvokingCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000)) {

      @SuppressWarnings("synthetic-access")
      @Override
      public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
                                        final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
        final ZonedDateTime valuationDate = ZonedDateTime.now(executionContext.getValuationClock());
        final HistoricalTimeSeriesBundle timeSeries = (HistoricalTimeSeriesBundle) inputs.getValue(ValueRequirementNames.YIELD_CURVE_INSTRUMENT_CONVERSION_HISTORICAL_TIME_SERIES);
        final ValueRequirement desiredValue = desiredValues.iterator().next();
        final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
        final String spotDateString = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_DATE);
        final LocalDate spotDate = LocalDate.parse(spotDateString, dateFormatter);
        final String offsetString = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_OFFSET);
        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) {
        //TODO: Move this to a seperate function
        final FixedIncomeStripIdentifierAndMaturityBuilder builder = new FixedIncomeStripIdentifierAndMaturityBuilder(OpenGammaExecutionContext.getRegionSource(executionContext),
                                                                                                                      OpenGammaExecutionContext.getConventionBundleSource(executionContext), executionContext.getSecuritySource(), OpenGammaExecutionContext.getHolidaySource(executionContext));
        final InterpolatedYieldCurveSpecificationWithSecurities curveSpecificationWithSecurities = builder.resolveToSecurity(curveSpec, marketData);
        return curveSpecificationWithSecurities;
      }

      private InterpolatedYieldCurveSpecification getCurveSpecification(final YieldCurveDefinition curveDefinition, final LocalDate curveDate) {
        final InterpolatedYieldCurveSpecification curveSpec = curveSpecBuilder.buildCurve(curveDate, curveDefinition);
        return curveSpec;
      }

    };
  }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.analytics.ircurve.InterpolatedYieldCurveSpecificationBuilder

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.