protected Set<ValueRequirement> getSensitivityRequirements(
     final SecuritySource secSource, final RawSecurity rawSecurity) {
   final Set<ValueRequirement> requirements = Sets.newHashSet();
   final Collection<FactorExposureData> decodedSensitivities =
       RawSecurityUtils.decodeFactorExposureData(secSource, rawSecurity);
   for (final FactorExposureData exposureEntry : decodedSensitivities) {
     requirements.add(getSensitivityRequirement(exposureEntry.getExposureExternalId()));
   }
   return requirements;
 }
示例#2
0
 private List<FactorExposure> convertToFactorExposure(
     List<FactorExposureData> factorExposureDataList) {
   List<FactorExposure> results = new ArrayList<FactorExposure>();
   for (FactorExposureData exposure : factorExposureDataList) {
     HistoricalTimeSeries exposureHTS =
         data()
             .getHistoricalTimeSeriesSource()
             .getHistoricalTimeSeries(
                 "EXPOSURE", exposure.getExposureExternalId().toBundle(), null);
     HistoricalTimeSeries convexityHTS =
         data()
             .getHistoricalTimeSeriesSource()
             .getHistoricalTimeSeries(
                 "CONVEXITY", exposure.getExposureExternalId().toBundle(), null);
     HistoricalTimeSeries priceHTS =
         data()
             .getHistoricalTimeSeriesSource()
             .getHistoricalTimeSeries("PX_LAST", exposure.getFactorExternalId().toBundle(), null);
     results.add(
         new FactorExposure(
             exposure.getFactorType().getFactorType(),
             exposure.getFactorName(),
             exposure.getNode(),
             priceHTS != null ? priceHTS.getUniqueId() : null,
             priceHTS != null ? priceHTS.getTimeSeries().getLatestValue() : null,
             exposureHTS != null ? exposureHTS.getUniqueId() : null,
             exposureHTS != null ? exposureHTS.getTimeSeries().getLatestValue() : null,
             convexityHTS != null ? convexityHTS.getUniqueId() : null,
             convexityHTS != null ? convexityHTS.getTimeSeries().getLatestValue() : null));
   }
   return results;
 }
 private FactorExposureData searchForBondTenorMatch(
     final Collection<FactorExposureData> exposures, final FixedIncomeStripWithSecurity strip) {
   for (final FactorExposureData exposure : exposures) {
     if (exposure.getFactorType().equals(FactorType.YIELD)
         && exposure.getFactorName().contains(BOND_TEXT)) {
       if (exposure.getNode() != null && exposure.getNode().length() > 0) {
         final Period nodePeriod = Period.parse("P" + exposure.getNode());
         if (strip.getTenor().getPeriod().toTotalMonths() == nodePeriod.toTotalMonths()) {
           return exposure;
         }
       }
     }
   }
   return null;
 }
 private DoubleMatrix1D getSensitivities(
     final SecuritySource secSource,
     final FunctionInputs inputs,
     final RawSecurity rawSecurity,
     final InterpolatedYieldCurveSpecificationWithSecurities curveSpec,
     final YieldAndDiscountCurve curve) {
   final Collection<FactorExposureData> decodedSensitivities =
       RawSecurityUtils.decodeFactorExposureData(secSource, rawSecurity);
   final double[] entries = new double[curveSpec.getStrips().size()];
   int i = 0;
   for (final FixedIncomeStripWithSecurity strip : curveSpec.getStrips()) {
     final FactorExposureData swapExternalSensitivitiesData =
         searchForSwapTenorMatch(decodedSensitivities, strip);
     if (swapExternalSensitivitiesData != null) {
       final ComputedValue computedValue =
           inputs.getComputedValue(
               getSensitivityRequirement(swapExternalSensitivitiesData.getExposureExternalId()));
       if (computedValue != null) {
         final ManageableHistoricalTimeSeries mhts =
             (ManageableHistoricalTimeSeries) computedValue.getValue();
         final Double value = mhts.getTimeSeries().getLatestValue();
         entries[i] =
             -value; // * (qty.doubleValue() ); // we invert here because OpenGamma uses -1bp shift
                     // rather than +1.  DV01 function will invert back.
       } else {
         s_logger.warn(
             "Value was null when getting required input data "
                 + swapExternalSensitivitiesData.getExposureExternalId());
         entries[i] = 0d;
       }
     } else {
       entries[i] = 0d;
     }
     i++;
   }
   // Quick hack to map in bond data.
   i = 0;
   for (final FixedIncomeStripWithSecurity strip : curveSpec.getStrips()) {
     final FactorExposureData bondExternalSensitivitiesData =
         searchForBondTenorMatch(decodedSensitivities, strip);
     if (bondExternalSensitivitiesData != null) {
       final ComputedValue computedValue =
           inputs.getComputedValue(
               getSensitivityRequirement(bondExternalSensitivitiesData.getExposureExternalId()));
       if (computedValue != null) {
         final ManageableHistoricalTimeSeries mhts =
             (ManageableHistoricalTimeSeries) computedValue.getValue();
         final Double value = mhts.getTimeSeries().getLatestValue();
         entries[i] -=
             value; // * (qty.doubleValue() ); // we invert here because OpenGamma uses -1bp shift
                    // rather than +1.  DV01 function will invert back.
       } else {
         s_logger.warn(
             "Value was null when getting required input data "
                 + bondExternalSensitivitiesData.getExposureExternalId());
       }
     }
     i++;
   }
   return new DoubleMatrix1D(entries);
 }