/**
  * Calculate the instrument sensitivity from the yield sensitivity, the jacobian matrix and the
  * coupon sensitivity.
  *
  * @param curveSensitivities The sensitivity to points of the yield curve.
  * @param curves The curve bundle.
  * @param couponSensitivity The sensitivity
  * @param jacobian The present value coupon sensitivity.
  * @return The instrument quote/rate sensitivity.
  */
 public DoubleMatrix1D calculateFromPresentValue(
     final Map<String, List<DoublesPair>> curveSensitivities,
     final YieldCurveBundle curves,
     final DoubleMatrix1D couponSensitivity,
     final DoubleMatrix2D jacobian) {
   final DoubleArrayList resultList = new DoubleArrayList();
   for (final String curveName : curves.getAllNames()) {
     final DoubleMatrix1D nodeSensitivity =
         new DoubleMatrix1D(
             (_parameterSensitivityCalculator.pointToParameterSensitivity(
                     curveSensitivities.get(curveName), curves.getCurve(curveName)))
                 .toArray(new Double[0]));
     final int n = nodeSensitivity.getNumberOfElements();
     final DoubleMatrix2D inverseJacobian = MATRIX_ALGEBRA.getInverse(jacobian);
     for (int i = 0; i < n; i++) {
       double sum = 0;
       for (int j = 0; j < n; j++) {
         sum +=
             -couponSensitivity.getEntry(i)
                 * inverseJacobian.getEntry(j, i)
                 * nodeSensitivity.getEntry(j);
       }
       resultList.add(sum);
     }
   }
   return new DoubleMatrix1D(resultList.toDoubleArray());
 }
Esempio n. 2
0
 public ChannelStorage(Symbol sym, double dft) {
   symbol = sym;
   defaultValue = dft;
   values = new DoubleArrayList(scores.elements().length);
   for (int i = size() - 1; i >= 0; i--) {
     values.add(defaultValue);
   }
 }
Esempio n. 3
0
 /**
  * Get the collection of values of this vector.
  *
  * @return The collection of all values in this vector.
  */
 public DoubleCollection values() {
   DoubleArrayList lst = new DoubleArrayList(size());
   IntIterator iter = keys.activeIndexIterator(false);
   while (iter.hasNext()) {
     int idx = iter.nextInt();
     lst.add(values[idx]);
   }
   return lst;
 }
 @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 Object volatilitySurfaceDataObject = inputs.getValue(_requirement);
   if (volatilitySurfaceDataObject == null) {
     throw new OpenGammaRuntimeException("Could not get " + _requirement);
   }
   @SuppressWarnings("unchecked")
   final VolatilitySurfaceData<LocalDate, Double> volatilitySurfaceData =
       (VolatilitySurfaceData<LocalDate, Double>) volatilitySurfaceDataObject;
   final int n = volatilitySurfaceData.getXs().length;
   final int m = volatilitySurfaceData.getYs().length;
   final DoubleArrayList t = new DoubleArrayList();
   final DoubleArrayList k = new DoubleArrayList();
   final DoubleArrayList sigma = new DoubleArrayList();
   final LocalDate[] xDates = volatilitySurfaceData.getXs();
   final Double[] y = volatilitySurfaceData.getYs();
   for (int i = 0; i < n; i++) {
     final Double time = DateUtils.getDifferenceInYears(now.toLocalDate(), xDates[i]);
     for (int j = 0; j < m; j++) {
       final Double strike = y[j];
       final Double vol = volatilitySurfaceData.getVolatility(xDates[i], y[j]);
       if (time != null && strike != null && vol != null) {
         t.add(time);
         k.add(strike);
         sigma.add(vol);
       }
     }
   }
   final Surface<Double, Double, Double> surface =
       InterpolatedDoublesSurface.from(
           t.toDoubleArray(), k.toDoubleArray(), sigma.toDoubleArray(), _interpolator);
   final VolatilitySurface volatilitySurface = new VolatilitySurface(surface);
   return Collections.singleton(new ComputedValue(_result, volatilitySurface));
 }
Esempio n. 5
0
 /**
  * Add a scored ID without boxing. The default value will be used for each channel.
  *
  * @param id The ID to add.
  * @param score The score for the ID.
  * @return The builder (for chaining).
  */
 public ScoredIdListBuilder add(long id, double score) {
   Preconditions.checkState(ids != null, "builder has been finished");
   ids.add(id);
   scores.add(score);
   for (ChannelStorage chan : channels.values()) {
     assert chan.values.size() == ids.size() - 1;
     chan.values.add(chan.defaultValue);
   }
   for (TypedChannelStorage chan : typedChannels.values()) {
     assert chan.values.size() == ids.size() - 1;
     chan.values.add(chan.defaultValue);
   }
   return this;
 }
 public DoubleMatrix1D calculateFromSimpleInterpolatedCurve(
     final Map<String, List<DoublesPair>> curveSensitivities,
     final YieldCurveBundle interpolatedCurves) {
   final DoubleArrayList resultList = new DoubleArrayList();
   for (final String curveName : interpolatedCurves.getAllNames()) {
     final DoubleMatrix1D nodeSensitivity =
         new DoubleMatrix1D(
             (_parameterSensitivityCalculator.pointToParameterSensitivity(
                     curveSensitivities.get(curveName), interpolatedCurves.getCurve(curveName)))
                 .toArray(new Double[0]));
     final int n = nodeSensitivity.getNumberOfElements();
     for (int i = 0; i < n; i++) {
       double sum = 0;
       for (int j = 0; j < n; j++) {
         sum += nodeSensitivity.getEntry(j);
       }
       resultList.add(sum);
     }
   }
   return new DoubleMatrix1D(resultList.toDoubleArray());
 }