/** * {@inheritDoc} * Vector root finders only need a single starting point; if more than one is provided, the first is used and any other points ignored. */ @Override public DoubleArray getRoot(Function<DoubleArray, DoubleArray> function, DoubleArray... startingPoint) { ArgChecker.notNull(startingPoint, "starting point"); return getRoot(function, startingPoint[0]); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullFunction() { DUMMY.getRoot(null, DoubleArray.EMPTY); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullVector() { DUMMY.getRoot(LINEAR, (DoubleArray) null); }
protected void assertYieldCurveBootstrap(final VectorRootFinder rootFinder, final double eps) { final int n = TIME_GRID.length; final double[] flatCurve = new double[n]; for (int i = 0; i < n; i++) { flatCurve[i] = 0.05; } final DoubleArray x0 = DoubleArray.copyOf(flatCurve); final DoubleArray x1 = rootFinder.getRoot(SWAP_RATES, x0); for (int i = 0; i < n; i++) { assertEquals(-Math.log(DUMMY_YIELD_CURVE.apply(TIME_GRID[i])) / TIME_GRID[i], x1.get(i), eps); } }
protected void assertLinear(final VectorRootFinder rootFinder, final double eps) { final DoubleArray x0 = DoubleArray.of(0.0, 0.0); final DoubleArray x1 = rootFinder.getRoot(LINEAR, x0); assertEquals(1.0, x1.get(0), eps); assertEquals(-1.0, x1.get(1), eps); }