@Override public DoublesPair build() { return new DoublesPair( first, second); }
@Override public double zValue(double x, double y) { return deformationFunction.apply(DoublesPair.of(x, y)).getValue(); }
public void test_compareTo() { DoublesPair p12 = DoublesPair.of(1d, 2d); DoublesPair p13 = DoublesPair.of(1d, 3d); DoublesPair p21 = DoublesPair.of(2d, 1d); assertTrue(p12.compareTo(p12) == 0); assertTrue(p12.compareTo(p13) < 0); assertTrue(p12.compareTo(p21) < 0); assertTrue(p13.compareTo(p12) > 0); assertTrue(p13.compareTo(p13) == 0); assertTrue(p13.compareTo(p21) < 0); assertTrue(p21.compareTo(p12) > 0); assertTrue(p21.compareTo(p13) > 0); assertTrue(p21.compareTo(p21) == 0); }
/** * Parses the quantity. * * @param row the CSV row to parse * @return the quantity, long first, short second * @throws IllegalArgumentException if the row cannot be parsed */ public static DoublesPair parseQuantity(CsvRow row) { Optional<Double> quantityOpt = row.findValue(QUANTITY_FIELD).map(s -> LoaderUtils.parseDouble(s)); if (quantityOpt.isPresent()) { double quantity = quantityOpt.get(); return DoublesPair.of(quantity >= 0 ? quantity : 0, quantity >= 0 ? 0 : -quantity); } Optional<Double> longQuantityOpt = row.findValue(LONG_QUANTITY_FIELD).map(s -> LoaderUtils.parseDouble(s)); Optional<Double> shortQuantityOpt = row.findValue(SHORT_QUANTITY_FIELD).map(s -> LoaderUtils.parseDouble(s)); if (!longQuantityOpt.isPresent() && !shortQuantityOpt.isPresent()) { throw new IllegalArgumentException( Messages.format("Security must contain a quantity column, either '{}' or '{}' and '{}'", QUANTITY_FIELD, LONG_QUANTITY_FIELD, SHORT_QUANTITY_FIELD)); } double longQuantity = ArgChecker.notNegative(longQuantityOpt.orElse(0d), LONG_QUANTITY_FIELD); double shortQuantity = ArgChecker.notNegative(shortQuantityOpt.orElse(0d), SHORT_QUANTITY_FIELD); return DoublesPair.of(longQuantity, shortQuantity); }
public void test_equals() { DoublesPair a = DoublesPair.of(1d, 2.0d); DoublesPair a2 = DoublesPair.of(1d, 2.0d); DoublesPair b = DoublesPair.of(1d, 3.0d); DoublesPair c = DoublesPair.of(2d, 2.0d); DoublesPair d = DoublesPair.of(2d, 3.0d); assertEquals(a.equals(a), true); assertEquals(a.equals(b), false); assertEquals(a.equals(c), false); assertEquals(a.equals(d), false); assertEquals(a.equals(a2), true); assertEquals(b.equals(a), false); assertEquals(b.equals(b), true); assertEquals(b.equals(c), false); assertEquals(b.equals(d), false); assertEquals(c.equals(a), false); assertEquals(c.equals(b), false); assertEquals(c.equals(c), true); assertEquals(c.equals(d), false); assertEquals(d.equals(a), false); assertEquals(d.equals(b), false); assertEquals(d.equals(c), false); assertEquals(d.equals(d), true); }
/** * Computes the sensitivity of the z-value with respect to the surface parameters. * <p> * This returns an array with one element for each x-y parameter of the surface. * The array contains one sensitivity value for each parameter used to create the surface. * * @param xyPair the pair of x-value and y-value at which the parameter sensitivity is computed * @return the sensitivity at the x/y/ point * @throws RuntimeException if the sensitivity cannot be calculated */ public default UnitParameterSensitivity zValueParameterSensitivity(DoublesPair xyPair) { return zValueParameterSensitivity(xyPair.getFirst(), xyPair.getSecond()); }
for (int i = 0; i < xValues.size(); i++) { ParameterMetadata pm = metadata.getParameterMetadata(i); sorted.put(DoublesPair.of(xValues.get(i), yValues.get(i)), ObjDoublePair.of(pm, zValues.get(i))); int pos = 0; for (Entry<DoublesPair, ObjDoublePair<ParameterMetadata>> entry : sorted.entrySet()) { sortedX[pos] = entry.getKey().getFirst(); sortedY[pos] = entry.getKey().getSecond(); sortedZ[pos] = entry.getValue().getSecond(); sortedPm[pos] = entry.getValue().getFirst(); Map<DoublesPair, Double> pairs = new HashMap<>(); for (int i = 0; i < xValues.size(); i++) { pairs.put(DoublesPair.of(xValues.get(i), yValues.get(i)), zValues.get(i));
public void coverage() { DoublesPair test = DoublesPair.of(1d, 2.0d); TestHelper.coverImmutableBean(test); }
/** * Obtains an instance from two {@code double} elements. * * @param first the first element * @param second the second element * @return a pair formed from the two parameters */ public static DoublesPair of(double first, double second) { return new DoublesPair(first, second); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 97440432: // first return ((DoublesPair) bean).getFirst(); case -906279820: // second return ((DoublesPair) bean).getSecond(); } return super.propertyGet(bean, propertyName, quiet); }
Map<DoublesPair, Double> sensiMap = new TreeMap<>(); for (int j = 0; j < size; ++j) { sensiMap.put(DoublesPair.of(exps[i][j][0], exps[i][j][1]), exps[i][j][2]); for (Entry<DoublesPair, Double> entry : sensiMap.entrySet()) { paramMetadata.add(SwaptionSurfaceExpiryTenorParameterMetadata.of( entry.getKey().getFirst(), entry.getKey().getSecond())); sensi.add(entry.getValue());