Package com.opengamma.core.marketdatasnapshot

Examples of com.opengamma.core.marketdatasnapshot.SnapshotDataBundle


        final Object dataObject = inputs.getValue(ValueRequirementNames.CURVE_MARKET_DATA);
        if (dataObject == null) {
          throw new OpenGammaRuntimeException("Could not get yield curve data");
        }
        final InterpolatedCurveSpecification specification = (InterpolatedCurveSpecification) specificationObject;
        final SnapshotDataBundle marketData = (SnapshotDataBundle) dataObject;
        final int n = marketData.size();
        final double[] times = new double[n];
        final double[] yields = new double[n];
        final double[][] jacobian = new double[n][n];
        Boolean isYield = null;
        int i = 0;
        for (final CurveNodeWithIdentifier node : specification.getNodes()) {
          if (node.getCurveNode() instanceof ContinuouslyCompoundedRateNode) {
            if (i == 0) {
              isYield = true;
            } else {
              if (!isYield) {
                throw new OpenGammaRuntimeException("Was expecting only continuously-compounded rate nodes; have " + node.getCurveNode());
              }
            }
          } else if (node.getCurveNode() instanceof DiscountFactorNode) {
            if (i == 0) {
              isYield = false;
            } else {
              if (isYield) {
                throw new OpenGammaRuntimeException("Was expecting only discount factor nodes; have " + node.getCurveNode());
              }
            }
          } else {
            throw new OpenGammaRuntimeException("Can only handle discount factor or continuously-compounded rate nodes; have " + node.getCurveNode());
          }
          //TODO add check to make sure it's only discounting or rate curve nodes
          final Double marketValue = marketData.getDataPoint(node.getIdentifier());
          final Tenor maturity = node.getCurveNode().getResolvedMaturity();
          if (marketValue == null) {
            throw new OpenGammaRuntimeException("Could not get market data for " + node);
          }
          times[i] = DateUtils.estimatedDuration(maturity.getPeriod()).toDays() / 365.0; //TODO check if this is correct
View Full Code Here


          final ValueProperties properties = ValueProperties.builder().with(CURVE, curveName).get();
          final CurveSpecification specification =
              (CurveSpecification) inputs.getValue(new ValueRequirement(ValueRequirementNames.CURVE_SPECIFICATION, ComputationTargetSpecification.NULL, properties));
          final CurveDefinition definition =
              (CurveDefinition) inputs.getValue(new ValueRequirement(ValueRequirementNames.CURVE_DEFINITION, ComputationTargetSpecification.NULL, properties));
          final SnapshotDataBundle snapshot =
              (SnapshotDataBundle) inputs.getValue(new ValueRequirement(ValueRequirementNames.CURVE_MARKET_DATA, ComputationTargetSpecification.NULL, properties));
          final int nNodes = specification.getNodes().size();
          final InstrumentDerivative[] derivativesForCurve = new InstrumentDerivative[nNodes];
          final double[] parameterGuessForCurves = new double[nNodes];
          int k = 0;
          for (final CurveNodeWithIdentifier node : specification.getNodes()) { // Node points - start
            final Double marketData = snapshot.getDataPoint(node.getIdentifier());
            if (marketData == null) {
              throw new OpenGammaRuntimeException("Could not get market data for " + node.getIdentifier());
            }
            parameterGuessForCurves[k] = 0.02; // For FX forward, the FX rate is not a good initial guess. // TODO: change this // marketData
            final InstrumentDefinition<?> definitionForNode = node.getCurveNode().accept(getCurveNodeConverter(conventionSource, holidaySource, regionSource,
View Full Code Here

    }

    @Override
    public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
        final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
      final SnapshotDataBundle marketData = new SnapshotDataBundle();
      final ExternalIdBundleResolver resolver = new ExternalIdBundleResolver(executionContext.getComputationTargetResolver());
      for (final CurveNodeWithIdentifier id : _specification.getNodes()) {
        if (id.getDataField() != null) {
          final ComputedValue value = inputs.getComputedValue(new ValueRequirement(id.getDataField(), ComputationTargetType.PRIMITIVE, id.getIdentifier()));
          if (value != null) {
            final ExternalIdBundle identifiers = value.getSpecification().getTargetSpecification().accept(resolver);
            if (id instanceof PointsCurveNodeWithIdentifier) {
              final PointsCurveNodeWithIdentifier pointsId = (PointsCurveNodeWithIdentifier) id;
              final ComputedValue base = inputs.getComputedValue(new ValueRequirement(pointsId.getUnderlyingDataField(), ComputationTargetType.PRIMITIVE, pointsId.getUnderlyingIdentifier()));
              if (base != null) {
                final ExternalIdBundle spreadIdentifiers = value.getSpecification().getTargetSpecification().accept(resolver);
                if (value.getValue() == null || base.getValue() == null) {
                  marketData.setDataPoint(spreadIdentifiers, null);
                } else {
                  marketData.setDataPoint(spreadIdentifiers, (Double) value.getValue() + (Double) base.getValue());
                }
              } else {
                s_logger.info("Could not get market data for {}", pointsId.getUnderlyingIdentifier());
              }
            } else {
              marketData.setDataPoint(identifiers, (Double) value.getValue());
            }
          } else {
            s_logger.info("Could not get market data for {}", id.getIdentifier());
          }
        } else {
          final ComputedValue value = inputs.getComputedValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, id.getIdentifier()));
          if (value != null) {
            final ExternalIdBundle identifiers = value.getSpecification().getTargetSpecification().accept(resolver);
            marketData.setDataPoint(identifiers, (Double) value.getValue());
          } else {
            s_logger.info("Could not get market data for {}", id.getIdentifier());
          }
        }
      }
View Full Code Here

        final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
        final Object dataObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE_MARKET_DATA);
        if (dataObject == null) {
          throw new OpenGammaRuntimeException("Could not get spread curve bucket data");
        }
        final SnapshotDataBundle data = (SnapshotDataBundle) dataObject;
        final ArrayList<Tenor> times = new ArrayList<>();
        final ArrayList<Double> rates = new ArrayList<>();
        for (final Map.Entry<ExternalIdBundle, Double> dataEntry : data.getDataPointSet()) {
          // TODO: The original code here was based on there just being one external ID per point and that having a value which is a period. It would
          // be better to use an id-scheme to tag such values just in case there are any other arbitrary tickers thrown into the bundle. The safest
          // interim approach is to use the first parseable one
          Period period = null;
          for (final ExternalId id : dataEntry.getKey()) {
View Full Code Here

    }
    final Object specObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE_SPEC);
    if (specObject == null) {
      throw new OpenGammaRuntimeException("Could not get yield curve specification for " + curveName + " and target " + target.getName());
    }
    final SnapshotDataBundle marketData = (SnapshotDataBundle) dataObject;
    final InterpolatedYieldCurveSpecificationWithSecurities yieldCurveSpec = (InterpolatedYieldCurveSpecificationWithSecurities) specObject;

    final int nNodes = yieldCurveSpec.getStrips().size();
    final double[] marketDataForCurve = new double[nNodes];
    final ISDAInstrumentTypes[] instruments = new ISDAInstrumentTypes[nNodes];
    final Period[] tenors = new Period[nNodes];
    int k = 0;

    DayCount cashDCC = null;
    DayCount fixDCC = null;
    BusinessDayConvention floatBadDayConv = null;
    Period paymentTenor = null;

    for (final FixedIncomeStripWithSecurity strip : yieldCurveSpec.getStrips()) {
      final String securityType = strip.getSecurity().getSecurityType();
      if (!(securityType.equals(CashSecurity.SECURITY_TYPE) || securityType.equals(SwapSecurity.SECURITY_TYPE) || securityType.equals(specObject))) {
        throw new OpenGammaRuntimeException("ISDA curves should only use Libor and swap rates");
      }
      final Double marketValue = marketData.getDataPoint(strip.getSecurityIdentifier());
      if (marketValue == null) {
        throw new OpenGammaRuntimeException("Could not get market data for " + strip);
      }
      final FinancialSecurity financialSecurity = (FinancialSecurity) strip.getSecurity();
      instruments[k] = securityType.equals(CashSecurity.SECURITY_TYPE) ? ISDAInstrumentTypes.MoneyMarket : ISDAInstrumentTypes.Swap;
View Full Code Here

      throw new OpenGammaRuntimeException(format("Double was expected in snapshot but Object instance of type %s found instead.", objResult.getClass()));
    }
  }

  private static SnapshotDataBundle createSnapshotDataBundle(final UnstructuredMarketDataSnapshot values) {
    final SnapshotDataBundle ret = new SnapshotDataBundle();
    for (final ExternalIdBundle target : values.getTargets()) {
      final Double value = queryDouble(values.getValue(target, MarketDataRequirementNames.MARKET_VALUE));
      ret.setDataPoint(target, value);
    }
    return ret;
  }
View Full Code Here

  private static VolatilityCubeData convertVolatilityCubeMarketData(final VolatilityCubeSnapshot volCubeSnapshot) {
    final Map<VolatilityPoint, ValueSnapshot> values = volCubeSnapshot.getValues();
    final HashMap<VolatilityPoint, Double> dataPoints = buildVolValues(values);
    final HashMap<Pair<Tenor, Tenor>, Double> strikes = buildVolStrikes(volCubeSnapshot.getStrikes());
    final SnapshotDataBundle otherData = createSnapshotDataBundle(volCubeSnapshot.getOtherValues());
    final VolatilityCubeData ret = new VolatilityCubeData();
    ret.setDataPoints(dataPoints);
    ret.setOtherData(otherData);
    ret.setATMStrikes(strikes);
    return ret;
View Full Code Here

TOP

Related Classes of com.opengamma.core.marketdatasnapshot.SnapshotDataBundle

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.