コード例 #1
0
 @Override
 public boolean equals(final Object o) {
   if (o == null) {
     return false;
   }
   if (!(o instanceof VolatilitySurfaceData)) {
     return false;
   }
   final VolatilitySurfaceData<?, ?> other = (VolatilitySurfaceData<?, ?>) o;
   return getDefinitionName().equals(other.getDefinitionName())
       && getSpecificationName().equals(other.getSpecificationName())
       && getTarget().equals(other.getTarget())
       && Arrays.equals(getXs(), other.getXs())
       && Arrays.equals(getYs(), other.getYs())
       && getXLabel().equals(other.getXLabel())
       && getYLabel().equals(other.getYLabel())
       && _values.equals(other._values);
 }
 @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));
 }