MultiCapFloorPricerGrid extends MultiCapFloorPricer { @Override public DoubleMatrix2D vegaFromCapletVols(double[] capletVolGridValues) { ArgumentChecker.notEmpty(capletVolGridValues, "null caplet volatilities"); ArgumentChecker.isTrue(_gridSize == capletVolGridValues.length, "Expect caplet vols on a (flatened) grid of {} strikes by {} expiries, so {} values. Given {} capletVols", getStrikes().length, getCapletExpiries().length, _gridSize, capletVolGridValues.length); double[] capletVega = new double[_gridSize]; int n = getNumCaplets(); for (int i = 0; i < n; i++) { int gridIndex = _optionsToGridMap[i]; capletVega[gridIndex] = BlackFormulaRepository.vega(getOption(i), capletVolGridValues[gridIndex]); } int nCaps = getNumCaps(); DoubleMatrix2D jac = new DoubleMatrix2D(nCaps, _gridSize); for (int i = 0; i < nCaps; i++) { double[] data = jac.getData()[i]; int[] indices = _capToGridMap[i]; for (int index : indices) { data[index] = capletVega[index]; } } return jac; } MultiCapFloorPricerGrid(List<CapFloor> caps, MulticurveProviderInterface curves); @Override double[] priceFromCapletVols(double[] capletVolGridValues); @Override DoubleMatrix2D vegaFromCapletVols(double[] capletVolGridValues); int getGridSize(); @Override DoublesPair[] getExpiryStrikeArray();  }
@Test(expectedExceptions = IllegalArgumentException.class) public void wrongNumCapletVolsVegaTest() { List<CapFloor> caps = getATMCaps(); MultiCapFloorPricerGrid pricer = new MultiCapFloorPricerGrid(caps, getYieldCurves()); double[] capletVols = new double[pricer.getNumCaplets()]; Arrays.fill(capletVols, 0.35); pricer.vegaFromCapletVols(capletVols); }